Richard Parnaby-King

Web Developer – PHP, Zend Framework and Actionscript 3

Posted on | | 2 Comments

Meta keywords and description used to be used by search engines to help work out what your website is about. Nowadays they are used to web applications to work out how to describe a specific page (for example, paste a link into Google+ and the meta description of the page will be fetched and shown). If you are writing a CMS that allows the user to populate the meta keywords and description of a page, but the user does not fill these fields, then it is nice to have a default value.

This post will share a custom View Helper that will check for your application adding empty meta details, and if there are, populating the values with default values from the application config.ini file.

First, we need to do add a folder structure for our view helpers. Create the following tree structure:

Now, we need to tell our application where to find our view helper. In the application bootstrap.php file add the following function:
$view = $this->getResource(‘view’);
$view->addHelperPath(‘RPK/View/Helper’, ‘RPK_View_Helper’);

This allows the application to access our view helper.

Here is the code for the view helper. We extend the already existing Zend view helper ‘HeadMeta’. Feel free to download this file
type == ‘name’ AND ($value->content == null OR strlen($value->content) === 0) AND ($value->name == ‘keywords’ OR $value->name == ‘description’))
//get options
$config = Zend_Controller_Front::getInstance()->getParam(‘bootstrap’)->getOptions();
switch ($value->name)
case ‘keywords’:
$setting = $config[‘default’][‘meta’][‘keywords’];
case ‘description’:
$setting = $config[‘default’][‘meta’][‘description’];
//set the value
if ($setting)
$value->content = $setting;

if (!$this->_isValid($value))
$e = new Zend_View_Exception(‘Invalid value passed to append; please use appendMeta()’);
throw $e;

return $this->getContainer()->append($value);



page = page object passed to view script from controller
->setName(‘keywords’, $this->page->metaKeywords)
->setName(‘description’, $this->page->metaDesc);

As you can see there is no special instantiation code needed.

Posted By:


  • Wow that was odd. I just wrote an extremely long comment but after I clicked
    submit my comment didn’t appear. Grrrr… well I’m not writing all that over again.
    Anyways, just wanted to say wonderful blog!

    • Hi Manuela,

      I’m sorry you lost your original comment. I have checked my logs and cannot find any trace of it. I am afraid it is lost forever.

      Thanks for the comment ;)



    Having nine years of programming experience in PHP, Zend Framework and ActionScript3, I have a very strong working knowledge of object orientated programming.

    I am a PC Gamer! Playing FPS, RTS, RPG and the occasional MMO since 1996 I have a huge number of a variety of fast-paced games.

  • Recent Posts

  • Categories