Yii拆分下拉列表

时间:2012-07-30 09:29:27

标签: php yii

我想在3个下拉列表字段(年,月和日)中拆分单个CActiveForm TextField。

我试试这段代码:

echo CHtml::activeDropDownList($model,'day', $model->getDays());
echo CHtml::activeDropDownList($model,'month', $model->getMonths());
echo CHtml::activeDropDownList($model,'year', $model->getYears());

但模型无法识别'day','month'和'year'字段,因为未在数据模型中定义。

有没有办法创建不依赖于模型的字段?

1 个答案:

答案 0 :(得分:0)

将这三个字段定义为模型中的变量,如

class myTable extends CActiveRecord
{
   public $day;
   public $month;
   public $year;
}

然后你就可以在你的CActiveForm中使用了。在调用$ model-> save();。

之前,在控制器中将这三个字段组合在一起