Zend 新手 - 控制器/视图问题
控制器称为MaintainusersController.php
视图称为maintainusers/listusers.phtml
如何将值从控制器推送到视图。
foreach ($users as $value){
/// do something here
}
Contoller iscalled MaintainusersController.php
View is called maintainusers/listusers.phtml
How do I push values from controller to view.
foreach ($users as $value){
/// do something here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在 $this->view 对象上创建变量,可以将值从控制器推送到视图,该对象是 Zend_Controller_Action 的成员。您在 $this->view 上创建的变量可以在视图脚本中从 $this 访问,因为视图对象封装在视图脚本中。
例如,如果您希望将用户名从控制器带到视图,您可以从您的操作方法中执行此操作:
您可以从视图脚本访问该方法:
在您的示例中,您正在推送一个值数组,您可以存储它直接在操作方法中的 $view 上:
然后从视图脚本中迭代:
You push values to the view from the controller by creating variables on the $this->view object, which is a member of Zend_Controller_Action. The variables you create on $this->view are accessible in the view script from $this, since the view object is encapsulated within the view script.
For example if you wish to bring the username from the controller to the view, you could this from your action method:
Which you can access from the view script as:
In your example you're pushing an array of values, which you can store directly on the $view in the action method:
And then iterate over from within the view script: