using zend view object as persistent storage
所以我在看本教程:
http://devzone.zend.com/article/3412
说
"在Zend Framework的MVC中,在大多数情况下,占位符没有意义;由于默认情况下所有控制器和布局之间都使用了相同的视图对象,因此您可以简单地将视图变量用作持久性存储机制。"
有人可以向我解释"持久存储机制"的工作原理吗?我尝试转到一个视图文件,设置$ this-> test ='something',然后转到另一个视图文件并回显$ this-> test
但是什么都没出现。...
如果您在同一请求中调用视图脚本并且顺序正确,则您的测试将起作用。
1 2 3 4 5 6 7 | view-script1.phtml Test one <p>nothing</p><?php $this->test = 'something'; ?> view-script2.phtml Test two <p><?php echo $this->test; ?></p> |
如果您没有以正确的顺序看到两个
此外,持久性存储的最佳示例是控制器。如果转发到其他动作甚至控制器,则可以通过它们传递数据
1 2 3 4 5 6 7 8 | controller1/actionOne $this->view->test = 'something'; controller2/actionTwo $this->view->test .= ' more'; in your viewscript echo $this->test; // will print"something more" |
持久性存储仅是Zend_View_Helper_Placeholder_Registry类使用的静态函数注册表,因为它是静态函数,因此可以与许多对象共享,因此在视图助手的上下文中称为持久性,持久性存储是此占位符的子类。