Hi all,

I'm pretty sure that others have done the same as me:

Base Controllers like My_BaseController and used as follows:
Module_SomeController extends MyLibrary_Controller_Base

Well, if so, you probably have done some methods just to shorten things a
bit.

I'll share some of my "convienience" methods and I hope you got some
ideas/feedback/bugs noticed and maybe some great convienience methods to
share...

I still would like to get Module Base Controller, but it does not autoload
itself =(
Module_SomeController extends Module_BaseController

br, Marko

-------------------------------------------------------------------

// output json without rendering any layouts/templates
protected function json($data)
{
        $this->_helper->json($data);
}

// Is the current action frontpage
protected function isFrontpage()
{
        $front = $this->getFrontController();

        return (boolean) $this->_module == $front->getDefaultModule() &&
$this->_controller == $front->getDefaultControllerName() && $this->_action
== $front->getDefaultAction();
}

// Disable layout and/or viewRenderer
protected function disableUI($layout = true, $viewRenderer = true)
{
        if ($layout) $this->_helper->layout->disableLayout();
                
        if ($viewRenderer) $this->_helper->viewRenderer->setNoRender();
}

// Set layout
protected function setLayout($layout)
{
        $this->_helper->layout->setLayout($layout);
}

// Set template
protected function setTemplate($template)
{
        $this->_helper->viewRenderer($template);
}

// Change the response segment (default is being $this->layout()->content
protected function setResponseSegment($segment)
{
        $this->_helper->viewRenderer->setResponseSegment($segment);
}

// Set page title
public function setTitle($title)
{
        $this->view->headTitle($this->view->page_title);
}

// Get Url by default route
public function url($module, $controller, $action, array $urlOptions =
array(), $reset = false, $encode = true)
{
        $urlOptions["module"] = $module;
        $urlOptions["controller"] = $controller;
        $urlOptions["action"] = $action;
                
        return $this->view->url($urlOptions, "default", $reset, $encode);
}

// Get Url by named route
public function urlByName($name, array $urlOptions = array(), $reset =
false, $encode = true)
{
        return $this->view->url($urlOptions, $name, $reset, $encode);
}
-- 
View this message in context: 
http://www.nabble.com/Base-Controller-convienience-methods-tp22036897p22036897.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to