I have 2 tables in database:
class Customers extends \Phalcon\Mvc\Model
{
public $id;
public $name;
public $lastname;
public function initialize()
{
$this->setSchema("public");
$this->hasMany('id', 'Customersactivation', 'cid', array('alias' => 'Customersactivation'));
}
}
class Customersactivation extends \Phalcon\Mvc\Model
{
public $id;
public $cid;
public $conbox;
public $cablein;
public function initialize()
{
$this->setSchema("public");
$this->belongsTo('cid', 'Customers', 'id', array('alias' => 'Customers'));
}
}
My edit action:
public function editAction($id)
{
if (!$this->request->isPost()) {
$customer = Customers::findFirstById($id);
if (!$customer) {
$this->flash->error("Nie znaleziono klienta o id= $id");
return $this->forward("customersactivation/index");
}
$this->view->form = new CustomersactivationForm($customer, array('edit' => true));
}
}
Form:
class CustomersactivationForm extends Form{
public function initialize($entity = null, $options = array())
{
if (!isset($options['edit'])) {
$element = new Text("id");
$this->add($element->setLabel("Id"));
} else {
$this->add(new Hidden("id"));
}
$name = new Text("name");
$name->setFilters(array('striptags', 'string'));
$name->addValidators(array(
new PresenceOf(array(
'message' => 'Name is required'
))
));
$this->add($name);
$lastname = new Text("lastname");
$lastname->addValidators(array(
new PresenceOf(array(
'message' => 'Lastname is required'
))
));
$this->add($lastname);
}
}
How to get values from second table inside that Form?