How can I override the form of FormHelper?

I need to change the behavior of $ form-> create, so I created an assistant to use instead of native formHelper:

SlugHelper:

App::import('Helper', 'Form'); class SlugFormHelper extends FormHelper { public function create() { return "error"; } } 

In AppController:

 public $helpers = array('SlugForm' => 'Form'); 

And in the view:

 $form->create(); 

but it still calls native $form->create();

+4
source share
3 answers

Just a thought - but shouldn't helpers be defined in the controller by doing something like this:

 public $helpers = array('SlugForm', 'Form'); 

Instead of what you had with "SlugForm => Form". Hope this helps!

0
source

I was just trying to do the same. I think it's pretty simple, just ...

 public $helpers = array('SlugForm'); 
0
source

try:

 public $helpers = array( 'Form' => array('className' => 'MyForm'), ); 
0
source

Source: https://habr.com/ru/post/1341040/


All Articles