我在布局文件中的一些自定义的占位符,如[Region_Contents] 现在我想用我的自定义HTML来替换这些占位符的布局呈现 喜欢的,而不是显示[Region_Contents]它可能会显示Zend框架呈现自定义占位布局
2
A
回答
1
您可以使用视图过滤器这一点。首先,我们必须实现像这样的Zend_Filter_Interface接口:
class My_View_Filter_PlaceholderReplacer implements Zend_Filter_Interface
{
public function filter($value)
{
return str_replace('[Region_Contents]', 'Hello this is test block', $value);
}
}
在上面的代码中,$值包含仅仅显示前视图的字符串表示。无论上面的函数返回什么,ZF在渲染视图时都会使用它。请注意,出于性能原因,我们使用str_replace而不是preg_replace。
接下来,我们需要告诉ZF使用我们刚制作的过滤器。你可以在bootstrap中做到这一点。
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initViewSettings()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addFilterPath('My/View/Filter', 'My_View_Filter');
$view->setFilter('PlaceholderReplacer');
...
}
...
}
欲了解更多信息,请参考以下链接:
0
如果它没有必要让你上面描述相同的语法,你可能只是使用标准Zend_View
占位符视图助手:http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.placeholder
希望帮助,
相关问题
- 1. Zend布局占位符?
- 2. 布局Zend框架
- 3. Zend框架布局
- 4. Zend框架布局
- 5. Zend框架2组自定义布局和setTerminate问题
- 6. 框架布局内定位
- 7. 自定义frappe框架html布局
- 8. 呈现自定义布局而不是应用程序布局
- 9. 布局在Zend框架1
- 10. zend布局占位符在哪里走?
- 11. Zend的导航自定义呈现
- 12. 自定义布局呈现“未发现”使用NLOG
- 13. 框架布局中的线性定位
- 14. zend框架自定义验证类
- 15. Zend框架3自定义元素
- 16. 在主布局错误CSS - Zend框架
- 17. Zend框架布局或视图lag
- 18. 默认和移动布局Zend框架
- 19. 添加CSS文件布局Zend框架
- 20. Zend框架通用布局和模块
- 21. Zend框架:添加形式布局
- 22. 自定义呈现UITableViewCell中的文本布局
- 23. Android框架修改:添加一个自定义布局
- 24. CSS自定义复选框布局
- 25. Android:SectionIndex对话框的自定义布局
- 26. Grails - 自定义Flash.message呈现
- 27. iOS“框架布局”
- 28. iPhone UITableViewController自定义布局
- 29. RadioButton的自定义布局
- 30. 自定义布局ListPreference
我只想过滤布局,我不想过滤视图。在上面的情况下,它正在过滤视图和布局,但我只需要过滤布局 – Tofeeq