由crud返回null对象生成的默认ActionAdmin。我已粘贴了操作代码。
public function actionAdmin()
{
$model=new Messages('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Messages']))
$model->attributes=$_GET['Messages'];
echo "<pre>";
print_r($model);exit;
$this->render('admin',array(
'model'=>$model,
));
}
/ ** *这是表“消息”的模型类。 * *以下是表'消息'中的可用列: * @property整数$ id * @property integer $ offer_id * @property string $ message * @property string $ created * / class Messages扩展了CActiveRecord { public function defaultScope(){ 返回数组( 'order'=&gt;'创建了DESC' ); } / ** * @return字符串关联的数据库表名称 * / public function tableName() { 返回'消息'; }
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('offer_id, user_id, message', 'required'),
array('offer_id, user_id', 'numerical', 'integerOnly'=>true),
array('message', 'length', 'max'=>2000),
array('message','filter','filter'=>array($obj=new CHtmlPurifier(),'purify')),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, offer_id, user_id, message, created', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
return array(
'offer' => array(self::BELONGS_TO, 'Offers', 'offer_id'),
'sender' => array(self::BELONGS_TO, 'Users', 'user_id')
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Message ID',
'offer_id' => 'Offer ID',
'user_id' => 'Sender',
'message' => 'Message',
'created' => 'Sent',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('offer_id',$this->offer_id);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('message',$this->message,true);
$criteria->compare('created',$this->created,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Messages the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
protected function beforeSave() {
if ($this->isNewRecord)
$this->created = date('Y-m-d H:i:s');
return parent::beforeSave();
}
}