當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CActiveRecord::hasAttribute方法代碼示例

本文整理匯總了PHP中CActiveRecord::hasAttribute方法的典型用法代碼示例。如果您正苦於以下問題:PHP CActiveRecord::hasAttribute方法的具體用法?PHP CActiveRecord::hasAttribute怎麽用?PHP CActiveRecord::hasAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CActiveRecord的用法示例。


在下文中一共展示了CActiveRecord::hasAttribute方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: usernameFieldsSet

 /**
  * Sets username fields of a model
  */
 public static function usernameFieldsSet(CActiveRecord $model, $username)
 {
     if ($model->hasAttribute('updatedBy')) {
         $model->updatedBy = $username;
     }
     if ($model->hasAttribute('createdBy') && $model->isNewRecord) {
         $model->createdBy = $username;
     }
 }
開發者ID:dsyman2,項目名稱:X2CRM,代碼行數:12,代碼來源:X2ChangeLogBehavior.php

示例2: hasAttribute

 public function hasAttribute($name)
 {
     //return true;
     $attr = get_object_vars($this);
     if (isset($attr[$name])) {
         return true;
     } else {
         return parent::hasAttribute($name);
     }
 }
開發者ID:hkhateb,項目名稱:linet3,代碼行數:10,代碼來源:basicRecord.php

示例3: update

 /**
  * main function called to update column in database
  *
  */
 public function update()
 {
     //set params from request
     $this->primaryKey = yii::app()->request->getParam('pk');
     $this->attribute = yii::app()->request->getParam('name');
     $value = Yii::app()->request->getParam('value');
     //checking params
     if (empty($this->attribute)) {
         throw new CException(Yii::t('zii', 'Property "attribute" should be defined.'));
     }
     if (empty($this->primaryKey)) {
         throw new CException(Yii::t('zii', 'Property "primaryKey" should be defined.'));
     }
     //loading model
     $this->model = CActiveRecord::model($this->modelClass)->findByPk($this->primaryKey);
     if (!$this->model) {
         throw new CException(Yii::t('editable', 'Model {class} not found by primary key "{pk}"', array('{class}' => get_class($this->model), '{pk}' => $this->primaryKey)));
     }
     $this->model->setScenario($this->scenario);
     //is attribute exists
     if (!$this->model->hasAttribute($this->attribute)) {
         throw new CException(Yii::t('editable', 'Model {class} does not have attribute "{attr}"', array('{class}' => get_class($this->model), '{attr}' => $this->attribute)));
     }
     //is attribute safe
     if (!$this->model->isAttributeSafe($this->attribute)) {
         throw new CException(Yii::t('zii', 'Model {class} rules do not allow to update attribute "{attr}"', array('{class}' => get_class($this->model), '{attr}' => $this->attribute)));
     }
     //setting new value
     $this->setAttribute($this->attribute, $value);
     //validate
     $this->model->validate(array($this->attribute));
     if ($this->model->hasErrors()) {
         $this->error($this->model->getError($this->attribute));
     }
     //save
     if ($this->beforeUpdate()) {
         //saving (only chnaged attributes)
         if ($this->model->save(false, $this->changedAttributes)) {
             $this->afterUpdate();
         } else {
             $this->error(Yii::t('zii', 'Error while saving record!'));
         }
     } else {
         $firstError = reset($this->model->getErrors());
         $this->error($firstError[0]);
     }
 }
開發者ID:janym,項目名稱:angular-yii,代碼行數:51,代碼來源:TbEditableSaver.php

示例4: getAttribute

 /**
  *### .getAttribute()
  *
  * Helper function to get an attribute from the data
  *
  * @param CActiveRecord $data
  * @param string $attribute the attribute to get
  *
  * @return mixed the attribute value null if none found
  */
 protected function getAttribute($data, $attribute)
 {
     if ($this->dataProvider instanceof CActiveDataProvider && $data->hasAttribute($attribute)) {
         return $data->{$attribute};
     }
     if ($this->dataProvider instanceof CArrayDataProvider || $this->dataProvider instanceof CSqlDataProvider) {
         if (is_object($data) && isset($data->{$attribute})) {
             return $data->{$attribute};
         }
         if (isset($data[$attribute])) {
             return $data[$attribute];
         }
     }
     return null;
 }
開發者ID:yinhe,項目名稱:yincart,代碼行數:25,代碼來源:TbExtendedGridView.php

示例5: hasAttribute

 public function hasAttribute($name)
 {
     if ($name == 'confirm_password') {
         return true;
     }
     return parent::hasAttribute($name);
 }
開發者ID:yasirgit,項目名稱:hotmall,代碼行數:7,代碼來源:User.php


注:本文中的CActiveRecord::hasAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。