Small note about the ContextSwitch action helper in Zend Framework

If you want to add other contexts to your actions in a controller, and your method names are for instance viewProjectAction or addTaskToProjectAction, you will need to refer to them using view-project and add-task-to-project respectively when setting up the ContextSwitch or AjaxContext helper.

<?php
class SomeController extends Zend_Controller_Action {
    public function init() {
        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('view-project', 'html')
                    ->addActionContext('add-task-to-project', 'html')
                    ->initContext();
    }

    public function viewProjectAction() {
        // ...
    }

    public function addTaskToProjectAction() {
        // ...
    }
}
Advertisements
This entry was posted in Technology and tagged , , , , , . Bookmark the permalink.

One Response to Small note about the ContextSwitch action helper in Zend Framework

  1. Frode says:

    Thanks, this one had me scratching my head for a while :-)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s