webfacer
webfacer

Reputation: 109

Load FormHelper into Controller CakePHP 1.3

So my problem is that i know how to load an Helper into the Controller but it´s only working for HtmlHelper not for FormHelper.

i load it into my method like this:

//this method is from an controller like page_controller    
function addField($pageID) {

    if($this->RequestHandler->isAjax()) {
        $this->autoRender = false;
    }

    App::import('Helper', 'Form');

    $form = new FormHelper();

    return $form->input('test');

}

I got some error like can´t load on unknown stdClas::$model etc.

HtmlHelper works well when i ouput it with link method i got a full rendered link in my view.

I wont only to load on Ajax an new input but it won´t work and i do not know why... Hope you understand my problem.

Upvotes: 0

Views: 1447

Answers (2)

Shyam
Shyam

Reputation: 300

Change this below code

App::import('Helper', 'Form');

$form = new FormHelper();

into this below code

App::import('Helper', 'Form');

$form = new FormHelper(new View());

then use $form like this $form->input('name');

you are missing (new View())

Upvotes: 0

mark
mark

Reputation: 21743

what you are doing there is awfully wrong. there is good reason why this doesn't and should never work your way.

use the normal MVC procedure as outlined in the documentation and tutorials. http://book.cakephp.org/

in your case this means that you NEED to always use a view template (/views/controllername/actionname.ctp) and put your form stuff in there.

Upvotes: 2

Related Questions