Zend Framework:检查是否设置了Zend View占位符 [英] Zend Framework: Check if Zend View Placeholder isset

查看:87
本文介绍了Zend Framework:检查是否设置了Zend View占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在回显之前检查Zend View占位符是否已设置?因为我想在输出之前在它之前加上-".

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.

我尝试了

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

但我知道了

致命错误:无法使用方法返回 写入上下文中的值 D:\ Projects \ Websites \ php \ ZendFramework \ LearningZF \ application \ layouts \ scripts \ layout.phtml 在第5行

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.

推荐答案

有关致命错误的原因,请参阅问题

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

因此您可以使用临时变量,也可以使用$this->placeholder()->getRegistry()->containerExists("key")返回布尔值.

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") : "";

这篇关于Zend Framework:检查是否设置了Zend View占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆