We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

form-entity bind

Hi,

I just would like to ask how can I bind both child-entity and parent-entity inside form (or perhaps do I need to merge the child and parent entity?).


<?php

use Phalcon\Forms\Form,
    Phalcon\Forms\Element\Text,

class EditUserForm extends Form
{

    public function initialize()
    {
       //Parent Entity = Users (id, addr_id, username, password)
       //Child Entity  = Addresses (id, street, address)

        $address = new Text('address');
        $this->add($address);
    }
}

What I want is to bind the users with addresses model in form. and get the fields inside address model (for instance: addresses column)

here is sample controller

<?php 

 class UsersController extends ControllerBase
 {
    public function editAction()
    {

       Users::findFirst()->Addresses->toArray(); //this returns a value..
       $this->view->form = new EditUserForm(Users::findFirst());
    }
 }

and when I render the address item in views

 {{ form.render('address') }} //no value.. 

Thanks in advance (Sorry for my noobness)!



58.4k
edited Mar '14

@braynm You can use as following

    class UsersController extends ControllerBase{
    public function editAction($ìd)
      {

        // Users::findFirst()->Addresses->toArray(); //this returns a value..
         $this->view->form = Users::findFirstById($id);
      }
    }