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
}
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
}
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:
$this->view->username = 'fred';
Which you can access from the view script as:
Username: <?php echo $this->username; ?>
In your example you're pushing an array of values, which you can store directly on the $view in the action method:
$this->view->users = $users;
And then iterate over from within the view script:
<ul>
<?php foreach ($this->users as $user) : ?>
<li><?php echo $this->user; ?></li>
<?php endforeach; ?>
</ul>