PhalconPHP: How to set a Selected option in SELECT tag

心已入冬 提交于 2019-12-04 19:41:01

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!