How can I override cake FormHelper?

894 views Asked by At

I need to change the $form->create behaviour, so I created a helper to use instead of the 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 the native $form->create();

3

There are 3 answers

1
rgubby On

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

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

Rather than what you had with "SlugForm => Form". Hope that helps!

0
Simon E. On

I've just been trying to do the same thing. I think it's quite simple, just...

public $helpers = array('SlugForm');
0
max masetti On

try with:

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