我需要:
form.created_from
,form.created_to
=&gt; table.created BETWEEN <form.created_from> AND <form.created_to>
#table model
class SomeModel extends CActiveRecord {
public function attributeLabels()
{
return array(
'id' => 'ID',
'created' => 'Created',
);
}
}
#form model
class SomeModelForm extends CFormModel {
public $id;
public $createdFrom;
public $createdTo;
}
#controller
class SomeController extends Controller {
public function actionSomeAction() {
$model = SomeModel('SomeModelForm');
}
}
错误:异常:未定义属性“SomeModel.createdFrom”。
如果不在createdFrom
中定义无用的属性(createdTo
,SomeModel
),是否可以这样做?
答案 0 :(得分:1)
你可以尝试这样,我希望它有效:
$model = new SomeModelForm;
$model->attributes = $_POST['SomeModelForm'];
$criteria = new CDbCriteria();
$criteria->addBetweenCondition('created', $model->createdFrom, $model->createdTo);
$result = SomeModel::model()->findAll($criteria);
答案 1 :(得分:0)
#form model
class SomeModelForm extends CFormModel {
public $id;
public $createdFrom;
public $createdTo;
public function search()
{
$criteria = new CDbCriteria();
$criteria->compare('id', $this->id);
$criteria->addBetweenCondition('created', $this->createdFrom, $this->createdTo);
return new CActiveDataProvider(SomeModel::model(), array(
'criteria' => $criteria,
));
}
}
#controller
class SomeController extends Controller {
public function actionSomeAction() {
$model = SomeModelForm();
}
}