如何在zend中将数据从控制器传递到视图?

时间:2022-10-09 23:12:10

I am starting in zend framework 1.11. How do we pass different $data value in view from controller to view like in codeigniter we pass like this.

我从zend framework 1.11开始。如何将视图中不同的$data值从控制器传递到视图中,就像我们在codeigniter中传递的那样。

$data['pass_one_thing'] = $this->model1->pass_all_mangoes();
$data['pass_another_thing'] = $this->model2->pass_all_oranges();
$this->load->view('viewfile', $data);

then in views we get values of $pass_one_thing and $pass_another_thing with foreach loops in same view file.

然后在视图中,我们得到$pass_one_thing和$pass_another_thing的值,每个循环在同一个视图文件中。

how do i pass from different model function in a same view ?

如何在相同的视图中传递不同的模型函数?

How do we get such thing in zend ? I am new to zend and bit confused.

我们怎么得到这样的东西?我是新手,有点困惑。

2 个解决方案

#1


7  

That can be done pretty much the same:

这也差不多可以做到:

$this->view->data = $data;

Or use the assign function:

或使用分配功能:

$this->view->assign('data', $data);

edit: How do I pass from different model function in a same view Not exactly sure but taking your exact example:

编辑:如何从不同的模型函数中传递到相同的视图中,虽然不是很确定,但是以你的例子为例:

$this->view->data['pass_one_thing'] = $this->model1->pass_all_mangoes();
$this->view->data['pass_another_thing'] = $this->model2->pass_all_oranges();
$this->load->view('viewfile', $data);

Then in your view you would access these trough:

然后在你看来,你会进入这些低谷:

$this->data['pass_one_thing']
$this->data['pass_another_thing']

#2


10  

You set it in your controller as:

在控制器中设置为:

$this->view->myVar = "something";

And then access it from the view:

然后从视图中访问它:

echo $this->myVar;

Or using assign like Wesley said.

或者使用像韦斯利说的分配。

#1


7  

That can be done pretty much the same:

这也差不多可以做到:

$this->view->data = $data;

Or use the assign function:

或使用分配功能:

$this->view->assign('data', $data);

edit: How do I pass from different model function in a same view Not exactly sure but taking your exact example:

编辑:如何从不同的模型函数中传递到相同的视图中,虽然不是很确定,但是以你的例子为例:

$this->view->data['pass_one_thing'] = $this->model1->pass_all_mangoes();
$this->view->data['pass_another_thing'] = $this->model2->pass_all_oranges();
$this->load->view('viewfile', $data);

Then in your view you would access these trough:

然后在你看来,你会进入这些低谷:

$this->data['pass_one_thing']
$this->data['pass_another_thing']

#2


10  

You set it in your controller as:

在控制器中设置为:

$this->view->myVar = "something";

And then access it from the view:

然后从视图中访问它:

echo $this->myVar;

Or using assign like Wesley said.

或者使用像韦斯利说的分配。