Search code examples
phpzend-frameworkzend-view

Zend Framework: Check if Zend View Placeholder isset


How can I check if a Zend View Placeholder isset before echo-ing it out? As I am wanting to prepend " - " to it before outputting it.

I tried

echo isset($this->placeholder('title')) 
    ? ' - ' . $this->placeholder('title') 
    : '';

But I got

Fatal error: Can't use method return value in write context in D:\Projects\Websites\php\ZendFramework\LearningZF\application\layouts\scripts\layout.phtml on line 5

On a side note, how come when I got this error, why isn't it shown in the Error View Script? The error was shown in a blank page without layout.


Solution

  • For the cause of the fatal error see the Question PHP : can’t use method return value in write context.

    So you could either use a temporary variable or $this->placeholder()->getRegistry()->containerExists("key") which returns a boolean.

    echo ($this->placeholder()->getRegistry()->containerExists("title")) ? " - " . $this->placeholder("title") : "";