Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Some issue by using fieldset in combination with ORM
  • I craete my ORM Model like the example and let create my Form by the
    Class Fieldset but it didn´t work like the example says to do it. When i
    try it this in my Controller i get this:

    action_edit($id)
    {
         $article = Model_article::query(array(
              'where' => array('id' => $id)
         ));
         'where' => array('id' => $id)
         ));

         $form = Fieldset::forge('article')->add_model($article)->populate($article, true)->build();
    }

    I get this output:

    <form action="http://mywebsite.com/article/edit/1" accept-charset="utf-8" method="post">
         <table>
         // --> i miss the inputs
         </table>
    </form>

    But when i use it this way the output is right:
    action_edit($id)
    {
         $fieldset = Fieldset::forge()->add_model('Model_Article');
         $form = $fieldset->form();
         $form->add('submit', null, array(
              'type' => 'submit',
              'value' => 'create',
              'class' => 'btn medium primary'
         ));
         $this->theme
              ->set_partial('body', 'creates')
              ->set('form', $form->build(), false);
    }

    What are the different between this two? 
  • Where in the first example do you pass the $form object to the view?

    Also, add_model() requires you to define the model properties in the Model. Did you do that?
  • After the $form variable i pass my the form into my view via

    $form = $fieldset->form();
    $form->add('submit', null, array(
            'type' => 'submit',
            'value' => 'create',
    'class' => 'btn medium primary'
        ));
    $this->theme->set_partial('body', 'creates')->set('form', $form->build(), false);

    And yes i did that with 

    $article = Model_Article::query(array('where' => array('id' => $id)))->get();

    because fuelphp docu says to do not use "find"-Method, it would change in the feature...
    but if i use normal find($id) method from model it works perfect.

    Thats why i asking how to use it know.

    Using it know like this:

    $article = Model_Article::find($id);
    $form = Fuel\Core\Fieldset::forge()->add_model($article);
    $form->add('submit', null, array(
            'type' => 'submit',
             'value' => 'create',
             'class' => 'btn medium primary'
        ));
    $this->theme->set_partial('body', 'creates')->set('form', $form->populate($article, true)->build(), false);
  • find() is not going to disappear. find() without parameters or find(null) is no longer supported, for that you need to use query().

    I personally pass the fieldset object itself, and run the build() in the view, but this should work fine too.

    add_model() reads the model's $_properties array to generate the form fields. My earlier question was: did you define these? If not, the fieldset doesn't have any data to generate input fields.
  • oh that yes yes i did define it.
  • Then I don't see why your form would not be generated. What if you do a

    Debug::dump($form)

    in your view?

    Fieldset uses the form.php config file to generate the form layout. Did you modify that? Or forgot to upgrade it after a Fuel core upgrade?
  • no but it works why i it didn´t work is because i used query method. When is use find method it works well, but is it possible to use query for fieldset?
  • There is no relation between a fieldset and how you query a model?
  • HarroHarro
    Accepted Answer
    With regards to find(), as I wrote before, find($id) is fine, and will not be removed.

    The problem with find() is that $id might be NULL, in which case find() did something completely different than you would expect (which is to return no answers), it would return a query object instead with all kinds of exceptions as a result. So passing nothing or NULL is no longer allowed. All other uses of find() will not change.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion