Search code examples
phpzend-frameworkzend-viewview-helpers

Zend Framework 1 View Helper: if value is not set, return default?


I wonder if there is a similar method already built-in in any of Zend Framework 1 view helpers?

<?
public function val(&$var, $default = '') {
// if $var is undefined, return $default, otherwise return $var
   return isset($var) ? $var : $default;
}
?>

and in View:

<? $this->val($myvar); ?>

I know I can create my own helper, just don't want to duplicate something that might have already been done and Zend API reference hangs all of my browsers Thanks.


Solution

  • You can use the declareVars view helper to assign your defaults beforehand.

    $this->view->declareVars(array("username"=>"Not Logged In");
    

    If that's not what you want I think you are left with implementing your own, a pretty trivial task.