Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Populate object with nested objects in a form

Hello.

This is my first post in this great forum.

I have two classes (I don't use ORM)

    class parent {

        public $id;

        public $name;

        public $ch;  <--- Child object

    }

    class child {

        public $id;

        public $name;

    }

Var_dump of parent object.

    object(parent)#95 (3) { 

        ["Id"]=> int(1) 

        ["name"]=> string(9) "FOO"  

        ["ch"]=> object(child)#132 (2)

        { 

            ["Id"]=> int(1) 

            ["name"]=> string(8) "BAR"

        }
    }

I have a Form with two text elements, but I cant't get the child name value inside this.

I want to send this object to edit the names in a volt view with and parent name appears ok , but I can't get child name (I have trycalling "ch.name" to the Text Element for example, but it does not works.

Thank you in advance.

Regards

Ángel



291
Accepted
answer
edited Sep '15

I have a possible solution using value option in my text element:

$chname="";
if($entity!=null){
        $chname=$entity->ch->name;
   }
$txtChildName = new Text("childName", array(
        "value" => $chname
    ));

Thank you.