将动态表单字段选项添加到FuelPHP模型属性

时间:2014-04-07 11:08:33

标签: php orm fuelphp

我在FuelPHP的模型_properties变量中创建了一个select表单元素:

protected static $_properties = array(
    'category_id' => array(
        'data_type' => 'int',
        'label' => 'Category',
        'form' => array(
            'type' => 'select',
            'options' => array()
        )
    )
);

我想将[category_id][form][options]设置为SQL查询的结果,但是这显然无法在类声明中完成,我尝试使用__construct()修改变量,此代码低于,但产生了错误。

 function _construct() {

     parent::__construct();

     self::$_properties['category_id']['form']['options'] = array('a');

}

我的问题是,如何使用FuelPHP将字段选项设置为动态?

1 个答案:

答案 0 :(得分:1)

你快到了。 Fuel提供了一个名为init的静态构造函数,它允许您分配静态属性。

function _init() {

     parent::_init();

     self::$_properties['category_id']['form']['options'] = array('a');

}