In our application there are situations, where we need presentational logic which will be shared between many views, elements, or layouts. For this purpose cakephp provides view helpers.
Some of them are:
CacheHelper, FormHelper, HtmlHelper, JsHelper, NumberHelper, Paginator, RSS, SessionHelper, extHelper, TimeHelper, etc.
Using and Configuring Helpers
$helpers property exist in every controller which manifest the lists of helpers that are available in the view. If you want to enable a helper in your view you have to first add the name of the helper to the controller’s $helpers array.
class IndexController extends AppController{
public $helpers = array('Custom');
}
Creating your own helper in cakephp is also easy. You need to follow some steps written below and you can make your own helper.
1. First open the folder app/View/Helper and create a new file named CustomHelper.php
2. Now add the following lines of code in this(CustomHelper.php) file.
<?php
class customHelper extends AppHelper{
public function customFunction($arg1){
return .$arg1.;
}
}
?>
3. Next, to add Custom helper in your application add followling lines of code in your AppController.php
class CustomsController extends AppController{
var $name = Tests;
var $helpers = array(custom);
..
}
4. Now, you can use Custom helper in your view file.
<?php
echo This helper is to make the content .$this->Mytest->testFunction(bold);
?>
Comment: This helper is used to make your content in bold letters.
0 Comment(s)