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

Use relationship data to setDefault in Form

Hi guys, I want to set value for a field in Form by this code:

$city = new Text('city');

$city->setDefault($userModel->City->title);

$city->setLabel('City');

$city->addValidators([ new PresenceOf() ]);

$this->add($city);

but I got this error:

Catchable fatal error: Object of class app\common\models\City could not be converted to string in E:\xampp\htdocs\phalcon\app\modules\frontend\views\user\profile.phtml on line 107

How can I set data from relationship ?

thanks.

Are you passing or binding a entity model when creating the form instance? remove it and pass an stdClass docs

Good luck