Simple Wrapper of Zend Controller

My simple wrapper of Zend Controller. It has 5 features including getParam, redirector, json and flash message.

 

/**
 * class App_Controller_Abstract
 *
 * @author kim
 */

class App_Controller_Abstract extends Zend_Controller_Action
{
    /**
     * wrapper of _getParam
     *
     * @return mixed|string
     */

    protected function _g($key, $default = null)
    {
        return $this->_getParam($key, $default);
    }

    /**
     * redirect URL of the form /module/controller/action/params
     *
     * @param  string $action
     * @param  string $controller
     * @param  string $module
     * @param  array  $params
     * @return void
     */

    protected function _r($action, $controller = null, $module = null, array $params = array())
    {
        $this->_helper->redirector($action, $controller, $module, $params);
    }

    /**
     * output json
     *
     * @return void
     */

    protected function _j($data, $isReturn = false, $params = array())
    {
        if ($isReturn) {
            return $this->_helper->json($data);
        } else {
            $this->_helper->json->sendJson($data, $params);
        }
    }

    /**
     * set flash message by namespace and content
     *
     * @param string $namespace
     * @param string $message
     * @return void
     */

    protected function _setFlashMessage($namespace, $message)
    {
        $flashMessenger = $this->_helper->flashMessenger;
        $flashMessenger->setNamespace($namespace);
        $flashMessenger->addMessage($message);
    }

    /**
     * get flash message
     *
     * @param string $namespace - namespace for message
     * @return string
     */

    protected function _getFlashMessage($namespace)
    {
        $flashMessenger = $this->_helper->flashMessenger;
        $flashMessenger->setNamespace($namespace);
        $messages = $flashMessenger->getMessages();
        if (count($messages) > 0) { return $messages[0]; }
        else { return ''; }
    }

}
Posted in Zend Framework | Tagged , | Leave a comment