R – Zend Framework’s Action helper doesn’t use a ViewRenderer

actionzend-framework

I'm trying to execute an action from the view using the Action helper like but although the action is been executed the output isn't displayed.

Here's part of my .phtml file:

<div id="active-users">
<?php echo $this->action('active', 'Users') ?>
</div>

The action works like this:

class UsersController extends Zend_Controller_Action
{
    function activeAction()
    {
        $model = new UsersModel();
        $this->view->users = $model->getActiveUsers();
    }
}

And there's another .phtml file that renders the list of users. The action works fine when called directly from /users/active but doesn't display anything when called from inside another .phtml file.

I've tracked the problem to the ViewRenderer not been available when called with action() helper… or at least not working as usual (automatically rendering the default .phtml file).

The content is displayed if I explicitly render the view inside the action but I need the ViewRender behaviour because I don't control the code of some of the actions I need to use.

Is there anyway to turn the ViewRenderer on while using the action() view helper? I'm open to replace the action() view helper if needed.

I forgot: I'm using PHP 5.2.8, Zend Framework 1.7.5, Apache 2.2 on Windows Vista.

Thanks

Best Answer

i think you should asign the active users from the controller or if you want you can use singleton on the models an use the directly in the views

$this->view = UsersModel::instance()->getActiveUsers();
Related Topic