Online Forum To Support Coders With Technical Assistance - Read Write Execute

Create Custom Helper and call from view in cakephp 3.x

Ankit Agrawal
Ankit Agrawal
Published on September 8, 2016 · 1 min read

To create a custom helper in cakephp first create a file in Helper folder and Helper classes should be suffixed with ‘Helper’.

example- (YourProject/src/view/Helper/CustomHelper.php)

CustomHelper.php is our new helper with Helper suffix.

Now in CustomHelper.php you can create function like this example

<?php
namespace App\View\Helper;

use Cake\View\Helper;

class CustomHelper extends Helper {


	
	public function yourhelperfunction()
	{		
		//your function code here
	}
}
?>

How to call custom helper function in view file

To call custom helper function from view file use

  $getresponse = $this->Custom->yourhelperfunction();
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article Call Controller function from webroot file in Cakephp 3 Next Article → Populate Select box dynamically by ajax in Cakephp