Reputation: 15008
I want to set the <option>
with the value coming from Db.
So far I tried this but not working:
$site_select = new Select('site_id', $this->_sites);
Upvotes: 1
Views: 3222
Reputation: 3884
Update
Generating the select using DB columns as Timothy recommended:
new Select('site_id', Sites::find(), array('using' => array('site_id', 'site_name')));
Setting the selected value of the given select:
$site_select->setDefault('YOUR_DB_VALUE');
However there is another lovely trick about Phalcon forms. You could pass your DB entity to the form class and your form will be auto populated.
Form:
class YourFormClass extends Phalcon\Forms\Form
{
public function initialize($entity = null, $options = null)
{
Controller:
$entity = YourModel::findFirst();
$form = new YourFormClass ($entity, $options);
Note that Form input names must match DB/Model columns.
Upvotes: 4