11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 19 • TEMPLATING WITH SMARTYwww.it-ebooks.infobegin at index offset 3 of the array. If a negative number is supplied, the startingposition will be determined by subtracting that number from the end of the array.step: Determines the stepping value used to traverse the array. By default, thisvalue is 1. For example, setting step to 3 will result in iteration taking place on arrayindices 0, 3, 6, 9, and so on. Setting step to a negative value will cause the iterationto begin at the end of the array and work backward.max: Determines the maximum number of times loop iteration will occur.show: Determines whether this section will actually display. You might use thisparameter for debugging purposes, and then set it to FALSE upon deployment.Consider two examples. The first involves iteration over a simple indexed array:$smarty = new Smarty;$titles = array("Pro <strong>PHP</strong>","Beginning Python","Pro <strong>MySQL</strong>");$smarty->assign("titles",$titles);$smarty->display("titles.tpl");The titles.tpl template contains the following:{section name=book loop=$titles}{$titles[book]}{/section}This returns the following:Pro <strong>PHP</strong>Beginning PythonPro <strong>MySQL</strong>Note the somewhat odd syntax, in that the section name must be referenced like an index valuewould within an array. Also note that the $titles variable name does double duty, serving as thereference for both the looping indicator and the actual variable reference.Now consider an example using an associative array:$smarty = new Smarty;// Create the array$titles[] = array("title" => "Pro <strong>PHP</strong>","author" => "Kevin McArthur","published" => "2008");$titles[] = array("title" => "Beginning Python",400

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!