0

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.

webfacer
  • 109
  • 5
  • 18
  • I am inclined to down vote for "intentional bad coding" here... but then again you might not have known better yet. please read the cookbook more carefully. – mark Jan 24 '12 at 22:40
  • Also, you'll want to use `App::iMport` in stead of `App::iNport`. But Mark is right, this is _not_ the way to go. – Joep Jan 25 '12 at 06:47
  • Sry i used wrong letter i will edit it. And i know that this way is wrong an that i can find another way with using MVC... Thats the reason why i am asking for because i can't found it after 2 days Research. I don't know why i am getting this answers insted of answers Wehre i can find it if somebody of you know that answers. I wouldn't ASK if i know where to find it in the cakebook. If you know how to use And where i can find my answer please tell the houl link where i can find or how to use correctly. I know the MVC Pattern. – webfacer Jan 25 '12 at 09:16

2 Answers2

2

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.

mark
  • 21,691
  • 3
  • 49
  • 71
  • i know that but how i can say that it don´t need to render the hole html with header all that stuff. because i need only the input field to render. Say one user press e ajax link that meens "Add inputfiled" and thats all i want to do not to render hole site. how i can realise this i found last year something about json how to render it and i think there is stuff how to give away the hole html body to render only what i need but do not know where to find it again in cakebook. – webfacer Jan 25 '12 at 13:14
  • 1
    you seem to be quite resistant in your ill-doings. it doesn't matter if you want to render a complete html site or only output a single char. you ALWAYS use the view to do that. you can set $this->layout = 'ajax' for example to avoid loading any extra layout. so there will only be this one form field then. – mark Jan 25 '12 at 13:26
0

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())

Shyam
  • 280
  • 1
  • 6
  • 17