Smarty caching

smarty3Smarty3 introduced a concept of template and data objects which can have a parent child relationship.
For this an additional parameter ‘parent’ was introduced which did change the parameter order of fetch and display to
($template, $parent = null, $cache_id = null, $compile_id = null)

So
$oSmarty->fetch ( $sTemplateName . ‘.tpl’, null, $iTemplateId )
should work.

NOCACHE attribute in include {include nocache}

The “nocache” in the {include} does tell Smarty that the content of the subtemplate shall not be merged into the cache file of main.tpl. The subtemplate creates it’s own cache file (which can have nocached sections). The cached content and rendered content of the nocache sections of the subtemplate is inserted into the output of the cached main.tpl each time the page is called.

Posted on December 10th, 2009 in Smarty 3 No Comments »

A flexible array_split function

Split the given array into n number of pieces

<br />
function array_split($array, $pieces=2) {<br />
	if ($pieces &amp;lt; 2)<br />
		return array($array);<br />
	$newCount = ceil(count($array)/$pieces);<br />
	$a = array_slice($array, 0, $newCount);<br />
	$b = array_split(array_slice($array, $newCount), $pieces-1);<br />
	return array_merge(array($a),$b);<br />
}<br />

Examples

<br />
$a = array(1,2,3,4,5,6,7,8,9,10);<br />
array_split($a, 2);    // array(array(1,2,3,4,5), array(6,7,8,9,10))<br />
array_split($a, 3);    // array(array(1,2,3,4), array(5,6,7), array(8,9,10))<br />
array_split($a, 4);    // array(array(1,2,3), array(4,5,6), array(7,8), array(9,10))<br />

Posted on December 8th, 2009 in Object Oriented PHP5 No Comments »

Web development common fonts to Windows & Mac

[style] p { margin: 10px 0; } table { width: 100%; margin: 0 0 10px; border: 2px solid Black; } caption { padding: 20px 0 5px; margin: 0; font: normal bold 1.35em Arial, Helvetica, sans-serif; text-align: left; color: Black; } th { padding: 2px 0; border: 1px solid Black; border-bottom-width: 3px; font: normal bold 1.15em Arial, Helvetica, sans-serif; } td { padding: 5px 20px; border: 1px solid Silver; font-size: 1.2em; } .bold { font-weight: bold; } td+td { font-weight: bold; } /* Mozilla only supports W3C defined properties for */ em { color: Gray; font-style: italic; } .symbol { font-size: 0.8em; } .mac { color: SteelBlue; } .mac a { color: MidnightBlue; } .notes { font-style: italic; margin-bottom: 30px; } [/style] Here you can find the list with the standard set of fonts common to all versions of Windows and their Mac substitutes, referred sometimes as "browser safe fonts". This is the reference I use when making web pages and I expect you will find it useful too.
Continue read »»»

Posted on June 16th, 2009 in HTML / CSS No Comments »

30 Tips to optimizing php code

PHP is a very fast programming language, but there is more to optimizing PHP than just speed of code execution. Here is the list of 30 short tips you can use for writing an optimized and more efficient PHP code. I considered myself a bit of a PHP pro until I started researching some of this stuff and realized that there is a whole realm of information out there about optimizing php that I didn’t know about. I hope you will be as surprised as I was about some of the things you might learn from this article.
Continue read »»»

Posted on June 9th, 2009 in PHP4 / PHP5 No Comments »

Sessions

PHP Sessions - Why Use Them?

A session is a way to store information (in the form of variables) to be used across multiple pages. Unlike a cookie, specific variable information is not stored on the users computer. It is also unlike other variables in the sense that we are not passing them individually to each new page, but instead retrieving them from the session we open at beginning of each page. Start a PHP Session Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent. Below is a simple script that you should place at the beginning of your PHP code to start up a PHP session.
session_start(); // start up your PHP session!
This tiny piece of code will register the user's session with the server, allow you to start saving user information and assign a UID (unique identification number) for that user's session.
Continue read »»»

Posted on April 14th, 2008 in Classes No Comments »