Chapter 5. Zym_Controller

Chapter 5. Zym_Controller

5.1. Action

The Zym_Controller_Action_Abstract class is an extension of Zend_Controller_Action.

5.1.1. Contexts Integration

Simple integration with the ContextSwitch and AjaxContext action helpers has been implemented (see the ZF ContextSwitch and AjaxContext action helpers for more info). The action controller will initialize contexts whenever $contexts or $ajaxable vars is defined. This simply makes the requirement of calling $contextHelper->initContext() optional.

Example 5.1. Using the Zym_Controller_Action contexts integration

<?php
class Default_IndexController extends Zym_Controller_Action_Abstract
{
    public $ajaxable = array(
        'index' => array('html', 'json')
    );
 
    public $contexts = array(
        'index' => array('xml', 'json')
    );
 
    public function indexAction()
    {
        // View
        $this->getView()->assign(array(
            'bar' => 'data',
            'data' => 'sdf'
        ));
    }
}
?>
/index/index/ = index.phtml
/index/index/ = index.ajax.phtml // Ajax request
/index/index/format/xml = index.xml.phtml
/index/index/format/json = Json encoded view object {'bar': 'data'}

5.1.2. View Accessor

A view accessor was added as $this->getView() for consistency.

public function indexAction()
{
    // Action code...
 
    // View
    $this->getView()->assign(array(
        'data'  => $data,
        'title' => $title
    ));
}

5.1.3. Goto method

The goto method provides a proxy to the redirector action helper. It has basically the same interface as the redirector's goto method. The only difference is the added $exit boolean. This boolean decides if the script should exit immediately after the redirect is issued.