Zend Framework: Simple steps to create Action Helper

Action helpers in Zend controller helps in abstracting concepts that are in common use for the project without cluttering the code base.

Zend’s official website and Zend casts gives detailed easy to use examples.

Step 1: Decide where you want the helper class for the controllers to reside inside the application folder. For this example, let us create a folder hierarchy under “application” folder

» application/controllers/Helper

Step 2: We will be creating a helper called “Printdata” in this example. For that to happen, we need to register the path for the helper file inside bootstrap file.

protected function _initControllerHelpers(){Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/Helper', 'Hellohelper');	}

As you can notice “Hellohelper” is the name that will be prefixed to the helper class (like Hellohelper_Printdata) that we will create under /controllers/Helper.

Step 3: Go inside the folder application/controllers/Helper and create a file called “Printdata.php”. We will write some code for testing our action helper.

class Hellohelper_Printdata extends Zend_Controller_Action_Helper_Abstract{

	public function testPrint($passData){
		if($passData != ""){	
			echo "Testing Printdata from action helper. Welcome ". $passData;
			echo "Testing action helper";


Step 3: Now access the zend action helper in one of Zend’s controller file using the command

	$this->_helper->Printdata->testPrint("Lorem ipsum");

Written by kurinchilamp

Website: http://

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *