Cakephp Override Htmlhelper::link
Solution 1:
Cake 2.1.5
I just implemented this and I wanted to point out a few things:
Your custom html helper should extend HTML helper (and don't forget to include the HTML helper class)
App::uses('HtmlHelper', 'View/Helper');
classCustomHtmlHelperextendsHtmlHelper{
//yadda yadda
}
Additionally, your call in AppController should not include the word Helper:
'Html'=> array('className' =>'CustomHtml'),
Solution 2:
In Cake 2.0
Create your OwnHelper class containing a link method, which extends HtmlHelper, in AppController specify:
$helpers = array('Html' => array('className' => 'OwnHelper'));
via ADmad
Solution 3:
Why don't you create your own custom helper and create a method that returns the HTMLHelper's link with the options set?
http://book.cakephp.org/view/102/Including-other-Helpers
class MyHelper extends AppHelper {
var $helpers = array('html');
function linkNoEscape($title, $url)
$options = array(); //set custom options, e.g. no escape
return$this->Html->link($title, $url, $options);
}
}
Solution 4:
I'm never comfortable overriding methods higher up in the hierarchy (ie in AppHelper) because there is always a good chance you break other helpers that are dependent.
Hoping to be able to comment soon, instead of giving rubbish half answers!
Also relevant: I heard that CakePHP 2.0 will allow helpers, components etc to be aliased. Eg you want to change the output from HtmlHelper, you can replace it with your own version without changing all your view templates.
Solution 5:
You could copy the original HTMLHelper
from cake/libs/view/helpers
to app/views/helpers
and modify the link()
method there.
Post a Comment for "Cakephp Override Htmlhelper::link"