简体   繁体   English

从控制器传递数组变量以在Joomla中查看

[英]Pass an array variable from controller to view in Joomla

I am redirecting to view from a controller and I want to send an array from controller to view. 我从控制器重定向到视图,我想从控制器发送一个数组以进行视图。 I am using : 我在用 :

$data = JRequest::getVar('jform', array(), 'post', 'array');

I want to pass this array to view named confirmation. 我想传递此数组以查看命名确认。

$this->setRedirect(JRout::-('index.php?option=com_contact&view=confirmation');

This redirects to view but how can I access the $data array in the view file ? 这将重定向到视图,但是如何访问视图文件中的$ data数组?

You shouldn't be sending data from the controller to the view. 您不应该将数据从控制器发送到视图。 Joomla is a MVC (model view controller) design, as such your business logic for getting, setting, and modifying data should be in your model. Joomla是MVC(模型视图控制器)设计,因此,用于获取,设置和修改数据的业务逻辑应该在模型中。

Modify your code to follow MVC design and you should have access to your data object in your view through the model. 修改代码以遵循MVC设计,并且您应该可以通过模型在视图中访问数据对象。

  • The controller's job is to get the view for the user 控制器的工作是为用户获取视图
  • The view's job is to display stuff for the the user and calls on the model 该视图的工作是为用户显示内容并调用模型
  • The model's job is to know about the data the view needs. 该模型的工作是了解视图所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM