if(Model中有个属性叫abc)怎么写 [ 新手入门 ]
我希望在控制器中加入一段代码,
if(Model中有个属性叫abc)
(.....)
else
(.....)
Model中有个属性叫abc,怎么写, model是根据数据库表结构自动生成的,也就是数据库中有个字段叫abc,
共 10 条回复
-
wanyun_liu 回复于 2012-06-05 13:40 举报
二楼。。。。。。顶
-
没有起效,为什么没有起效呢?每次 isset($model->During) 都是返回 false,即
$model->During=date('Y-m-01',strtotime('-5 month'))
没有执行,这是为什么呢?
我的controllerpublic function actionAdmin() { $model=new Test('search'); $model->unsetAttributes(); // clear any default values if(isset($model->During)) $model->During=date('Y-m-01',strtotime('-5 month')); if(isset($_GET['Test'])) $model->attributes=$_GET['Test']; $this->render('admin',array( 'model'=>$model, )); }
我的model
<?php /** * This is the model class for table "Test". * * The followings are the available columns in table 'Test': * @property integer $a * @property string $depOrProfitName * @property string $During */ class Test extends CActiveRecord { /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Test 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 'Test'; } /** * @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('depOrProfitName', 'length', 'max'=>500), array('During', 'safe'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('a, depOrProfitName, During', '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( 'a' => 'A', 'depOrProfitName' => 'Dep Or Profit Name', 'During' => 'During', ); } /** * 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('a',$this->a); $criteria->compare('depOrProfitName',$this->depOrProfitName,true); $criteria->compare('During',$this->During,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } }
onunix china
注册时间:2012-03-19
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝2
- 金钱1145
- 威望0
- 积分1145