I have a one-to-many relationship that looks like:
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
public $id;
public $name;
public function initialize()
{
$this->hasMany('id', 'Parts', 'part_id');
}
}
class Parts extends Model
{
public $id;
public $part_id;
public $part_name;
public function initialize()
{
$this->belongsTo('part_id', 'Robots', 'id');
}
}
and the form looks like:
class RobotsForm extends Form
{
public function initialize($entity = null, $options = array())
{
$name = new Text("name")
$name->setLabel("Robot Name");
$this->add($name);
foreach ($entity->parts as $part) {
// how to add the part name?
// $this->add(new Text("part_name[]"));
}
}
}
Using volt for rendering, how can I iterate over all the robot parts and add a text field for each part name? e.g.,
{% for element in form.get('parts') %}
{{ element.render("part_name") }}
{% endfor %}