- individual stylesheets are applied to a page
- Client-side script can be added
- Metadata such a description and keywords
Tuesday, 13 May 2008
Helpers are the way forward
Saturday, 3 May 2008
Zend and XSLT as a template engine
If you have XML data that you need displayed, turn off automatic view rendering within you bootstrap file with
$controller->setParam('noViewRenderer', true);This gives you more control over how Zend renders views. Then, in your controller action , create a new view and assign some variable from you application logic. You need to tell the view where the script is to execute. You do this using $view->setScriptPath('...');. Once this points to the right directory, you can add a script in there you want the view to run. You do this by calling the render method of the view instance you create, passing it a single string parameter as the script you want it to run. As the contents of the script is returned, the whole thing needs to either be echoed or printed from the controller action.
Within the view script, print anything you want to be rendered on the page. So here you can pair up the xml data passed from the controller action using $this and an XSLT stylesheets you want to transform.
Brilliant hey? I sort of get this stuff.
Thursday, 1 May 2008
Differences between echo and print
echo "$variable" will get echo to replace the variable name with it's value. If echo is used with single quotes it won't work.Saturday, 22 March 2008
Printing Arrays in PHP
print_r(); to debug an array. I guess echo and print just produce array.When displaying stuff in web pages use a
foreach loop.
Thursday, 20 March 2008
MySQL wrapper class
Smarty: A PHP template Engine
libs/ directory. When copying in unix, remember to add option -r to go into the internals/ and plugins/ directories within libs/. With those files saved somewhere, your PHP has to find one file in particular-Smarty.class.php (they also seem to be quite strict about the capital "S" in "Smarty"). That file needs to be referenced with an absolute path. This can be done a number of ways, look them up at Smarty's documentation. One cool way I've found so far is this:
// Use the absolute path for Smarty.class.php
$base_path= basename(dirname(__FILE__));
require($base_path.'/Smarty/Smarty.class.php');
Of course this assumes that you're writing this in a file which is in the document root of your webserver, and that the Smarty files are located further down in the folder
Smarty/. The require_once is similar to PHP's include statement apart from it will result in an error if it can't find the file (include will just try and not care if it can't) and the _once part ensures there's no errors if you accidentally try to require it again.Within that
Smarty directory, make four folders: templates, templates_c, cache and configs. Link these files up with your code with
$smarty = new Smarty();
$smarty->template_dir = $base_path.'Smarty/templates';
$smarty->compile_dir = $base_path.'Smarty/templates_c';
$smarty->cache_dir = $base_path.'Smarty/cache';
$smarty->config_dir = $base_path.'Smarty/configs';
Put this immediately after the
required_once statement. Then start making templates and go.
Wednesday, 19 March 2008
PHP: the ? operator
? in PHP is shorthand for an if..else statement. It works like this{expression} ? return_when_expression_true : return_when_expression_false;Notice the
? and the : to separate everything apart.
Casting in PHP
$test = 1234;
$test_string = (string)$test;Simple.
Tuesday, 18 March 2008
.inc files and libraries
require_once() to include files to use as a library. These files get interpreted by the interpreter but aren't called directly. They are conventionally given a .inc file extension, and they allow you to call functions and stuff hidden inside them. Quite useful.