Custom controller

From SocialStrap Wiki
Jump to: navigation, search

In this tutorial we will create additional controller called 'custom' with a single action called 'hello'


Create a new file called app/core/controllers/CustomController.php with this content:

<?php

class CustomController extends Zend_Controller_Action
{

	/**
	 * Hello action
	 */
	public function helloAction()
	{
		// switch to wide layout
		$this->_helper->_layout->setLayout('layout_wide');
	}

}


Now we can create appropriate layout file to hold some html content app\core\views\layout\custom\hello.phtml

<div>
	Hello world!
</div


We must allow access by adding this to the bottom of access control list constructor function app/core/plugins/AccessCheck.php

		// custom controllers, restore after updating
		$this->acl->addResource(new Zend_Acl_Resource('custom'))
		->addResource(new Zend_Acl_Resource('custom/hello'), 'custom')
		;

		$this->acl->allow('guest', array(
			'custom',
		));


Now point your browser to your new controller/action like this example.com/custom/hello