Yii 模型有问题,我创建了一个带有两个日期时间列的 MySQL 表。
并使用 gii 创建模型。问题是当我从模型中获取数据时,日期时间字段为空。
<?php
/**
* This is the model class for table "Template".
*
* The followings are the available columns in table 'Template':
* @property string $tmpId
* @property integer $fanPageId
* @property string $name
* @property string $title
* @property string $description
* @property string $headerFile
* @property string $msgNotTlt
* @property string $msgNotMsg
* @property string $msgNotImg
* @property string $msgNotLnk
* @property string $terms
* @property string $strProm
* @property string $endProm
*/
class Template extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Template the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'Template';
}
/**
* @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('fanPageId', 'numerical', 'integerOnly'=>true),
array('name, title, description, headerFile, msgNotTlt, msgNotMsg, msgNotImg, msgNotLnk, terms', 'length', 'max'=>11),
array('strProm, endProm', 'safe'),
//array('endProm, strProm', 'type', 'type'=>'datetime', 'datetimeFormat'=>'yyyy/M/d H:m:s'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('tmpId, fanPageId, name, title, description, headerFile, msgNotTlt, msgNotMsg, msgNotImg, msgNotLnk, terms, strProm, endProm', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'tmpId' => 'Tmp',
'fanPageId' => 'Fan Page',
'name' => 'Name',
'title' => 'Title',
'description' => 'Description',
'headerFile' => 'Header File',
'msgNotTlt' => 'Msg Not Tlt',
'msgNotMsg' => 'Msg Not Msg',
'msgNotImg' => 'Msg Not Img',
'msgNotLnk' => 'Msg Not Lnk',
'terms' => 'Terms',
'strProm' => 'Str Prom',
'endProm' => 'End Prom',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('tmpId',$this->tmpId,true);
$criteria->compare('fanPageId',$this->fanPageId);
$criteria->compare('name',$this->name,true);
$criteria->compare('title',$this->title,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('headerFile',$this->headerFile,true);
$criteria->compare('msgNotTlt',$this->msgNotTlt,true);
$criteria->compare('msgNotMsg',$this->msgNotMsg,true);
$criteria->compare('msgNotImg',$this->msgNotImg,true);
$criteria->compare('msgNotLnk',$this->msgNotLnk,true);
$criteria->compare('terms',$this->terms,true);
$criteria->compare('strProm',$this->strProm,true);
$criteria->compare('endProm',$this->endProm,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}