Location: PHPKode > projects > Web2.0 community/group web site > web20groups_pre-alpha-2/include/CustomControllerAction.php
<?php

class CustomControllerAction extends Zend_Controller_Action
{
	public $db;
	public $messenger;

	public function init()
	{
		$this->db = Zend_Registry::get('db');

		$this->messenger = $this->_helper->_flashMessenger;
	}

	public function getUrl($action = null, $controller = null)
    {
//		$url  = rtrim($this->getRequest()->getBaseUrl(), '/') . '/';
		$url = $this->_helper->url->simple($action, $controller);
        return '/' . ltrim($url, '/');
    }

	public function getCustomUrl($options, $route = null)
	{
		return $this->_helper->url->url($options, $route);
	}

	public function preDispatch()
	{
		$auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity())
		{
			$this->view->authenticated = true;
			$this->view->identity = $auth->getIdentity();
			$this->username= $this->view->identity->username;
			$this->user_id= $this->view->identity->user_id;
            $this->user_type = $this->view->identity->user_type;
		}
		else
		{
			$this->view->authenticated = false;
			$this->username= '';
			$this->user_id= '';
            $this->user_type= '';
		}
	}

	public function postDispatch()
	{
		$this->view->messages = $this->messenger->getMessages();

		$this->view->isXmlHttpRequest = $this->getRequest()->isXmlHttpRequest();
	}

	//TODO: Need to check out this function on how it works, when AJAX request is handled
	public function sendJson($data)
    {
		$this->_helper->viewRenderer->setNoRender();

		$this->getResponse()->setHeader('content-type', 'application/json');
		echo Zend_Json::encode($data);
	}

}

?>
Return current item: Web2.0 community/group web site