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


PHP ActiveRecord::refresh方法代碼示例

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


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

示例1: beforeSave

 /**
  * @throws Exception
  * @throws NotSupportedException
  */
 public function beforeSave()
 {
     if ($this->node !== null && !$this->node->getIsNewRecord()) {
         $this->node->refresh();
     }
     switch ($this->operation) {
         case self::OPERATION_MAKE_ROOT:
             $this->owner->setAttribute($this->parentAttribute, null);
             if ($this->sortable !== false) {
                 $this->owner->setAttribute($this->behavior->sortAttribute, 0);
             }
             break;
         case self::OPERATION_PREPEND_TO:
             $this->insertIntoInternal(false);
             break;
         case self::OPERATION_APPEND_TO:
             $this->insertIntoInternal(true);
             break;
         case self::OPERATION_INSERT_BEFORE:
             $this->insertNearInternal(false);
             break;
         case self::OPERATION_INSERT_AFTER:
             $this->insertNearInternal(true);
             break;
         default:
             if ($this->owner->getIsNewRecord()) {
                 throw new NotSupportedException('Method "' . $this->owner->className() . '::insert" is not supported for inserting new nodes.');
             }
     }
 }
開發者ID:karsel,項目名稱:yii2-adjacency-list,代碼行數:34,代碼來源:AdjacencyListBehavior.php

示例2: beforeUpdate

 /**
  * @throws Exception
  */
 public function beforeUpdate()
 {
     if ($this->node !== null && !$this->node->getIsNewRecord()) {
         $this->node->refresh();
     }
     switch ($this->operation) {
         case self::OPERATION_MAKE_ROOT:
             if ($this->treeAttribute === null) {
                 throw new Exception('Can not move a node as the root when "treeAttribute" is not set.');
             }
             if ($this->isRoot()) {
                 throw new Exception('Can not move the root node as the root.');
             }
             break;
         case self::OPERATION_INSERT_BEFORE:
         case self::OPERATION_INSERT_AFTER:
             if ($this->node->isRoot()) {
                 throw new Exception('Can not move a node before/after root.');
             }
         case self::OPERATION_PREPEND_TO:
         case self::OPERATION_APPEND_TO:
             if ($this->node->getIsNewRecord()) {
                 throw new Exception('Can not move a node when the target node is new record.');
             }
             if ($this->owner->equals($this->node)) {
                 throw new Exception('Can not move a node when the target node is same.');
             }
             if ($this->node->isChildOf($this->owner)) {
                 throw new Exception('Can not move a node when the target node is child.');
             }
     }
 }
開發者ID:nuclearman,項目名稱:yii2-nested-sets-1,代碼行數:35,代碼來源:NestedSetsBehavior.php

示例3: beforeSave

 /**
  * @throws Exception
  * @throws NotSupportedException
  */
 public function beforeSave()
 {
     if ($this->node !== null && !$this->node->getIsNewRecord()) {
         $this->node->refresh();
     }
     switch ($this->operation) {
         case self::OPERATION_MAKE_ROOT:
             $this->makeRootInternal();
             break;
         case self::OPERATION_PREPEND_TO:
             $this->insertIntoInternal(false);
             break;
         case self::OPERATION_APPEND_TO:
             $this->insertIntoInternal(true);
             break;
         case self::OPERATION_INSERT_BEFORE:
             $this->insertNearInternal(false);
             break;
         case self::OPERATION_INSERT_AFTER:
             $this->insertNearInternal(true);
             break;
         default:
             if ($this->owner->getIsNewRecord()) {
                 throw new NotSupportedException('Method "' . $this->owner->className() . '::insert" is not supported for inserting new nodes.');
             }
             $item = $this->owner->getAttribute($this->itemAttribute);
             $path = $this->getParentPath();
             $this->owner->setAttribute($this->pathAttribute, ($path !== null ? $path . $this->delimiter : null) . $item);
     }
 }
開發者ID:paulzi,項目名稱:yii2-materialized-path,代碼行數:34,代碼來源:MaterializedPathBehavior.php

示例4: beforeUpdate

 /**
  * @throws Exception
  */
 public function beforeUpdate()
 {
     if ($this->node !== null && !$this->node->getIsNewRecord()) {
         $this->node->refresh();
     }
     switch ($this->operation) {
         case self::OPERATION_MAKE_ROOT:
             if ($this->treeAttribute === false) {
                 throw new Exception('Can not move a node as the root when "treeAttribute" is false.');
             }
             if ($this->owner->isRoot()) {
                 throw new Exception('Can not move the root node as the root.');
             }
             if (!$this->treeAttributeById) {
                 if ($this->owner->getOldAttribute($this->treeAttribute) === $this->owner->getAttribute($this->treeAttribute)) {
                     throw new Exception('Can not move a node as the root when its tree attribute "' . $this->treeAttribute . '" is not changed.');
                 }
                 if ($this->owner->find()->andWhere([$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute), $this->leftAttribute => 1])->one()) {
                     throw new Exception('Can not move a node as the root when another root with this "' . $this->treeAttribute . '" already exists.');
                 }
             }
             break;
         case self::OPERATION_INSERT_BEFORE:
         case self::OPERATION_INSERT_AFTER:
             if ($this->node->isRoot()) {
                 throw new Exception('Can not move a node when the target node is root.');
             }
         case self::OPERATION_PREPEND_TO:
         case self::OPERATION_APPEND_TO:
             if ($this->node->getIsNewRecord()) {
                 throw new Exception('Can not move a node when the target node is new record.');
             }
             if ($this->owner->equals($this->node)) {
                 throw new Exception('Can not move a node when the target node is same.');
             }
             if ($this->node->isChildOf($this->owner)) {
                 throw new Exception('Can not move a node when the target node is child.');
             }
     }
 }
開發者ID:Oreolek,項目名稱:yii2-nested-sets,代碼行數:43,代碼來源:NestedSetsBehavior.php

示例5: refresh

 /**
  * @inheritdoc
  */
 public function refresh()
 {
     if (!parent::refresh()) {
         return false;
     }
     $dynCol = static::dynamicColumn();
     if (isset($this->attributes[$dynCol])) {
         $this->_dynamicAttributes = static::dynColDecode($this->attributes[$dynCol]);
     }
     return true;
 }
開發者ID:nineinchnick,項目名稱:yii2-dynamic-ar,代碼行數:14,代碼來源:DynamicActiveRecord.php

示例6: beforeSave

 /**
  * @throws Exception
  * @throws NotSupportedException
  */
 public function beforeSave()
 {
     if ($this->node !== null && !$this->node->getIsNewRecord()) {
         $this->node->refresh();
     }
     switch ($this->operation) {
         case self::OPERATION_MAKE_ROOT:
             $item = $this->owner->getAttribute($this->itemAttribute);
             if ($item !== null) {
                 $this->owner->setAttribute($this->pathAttribute, $item);
             }
             $this->owner->setAttribute($this->depthAttribute, 0);
             break;
         case self::OPERATION_PREPEND_TO:
             $this->checkNode(false);
             $item = $this->owner->getAttribute($this->itemAttribute);
             if ($item !== null) {
                 $path = $this->node->getAttribute($this->pathAttribute);
                 $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item);
             }
             $this->owner->setAttribute($this->depthAttribute, $this->node->getAttribute($this->depthAttribute) + 1);
             if ($this->sortAttribute !== null) {
                 $to = $this->node->getChildren()->orderBy(null)->min($this->sortAttribute);
                 $to = $to !== null ? $to - $this->step : 0;
                 $this->owner->setAttribute($this->sortAttribute, $to);
             }
             break;
         case self::OPERATION_APPEND_TO:
             $this->checkNode(false);
             $item = $this->owner->getAttribute($this->itemAttribute);
             if ($item !== null) {
                 $path = $this->node->getAttribute($this->pathAttribute);
                 $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item);
             }
             $this->owner->setAttribute($this->depthAttribute, $this->node->getAttribute($this->depthAttribute) + 1);
             if ($this->sortAttribute !== null) {
                 $to = $this->node->getChildren()->orderBy(null)->max($this->sortAttribute);
                 $to = $to !== null ? $to + $this->step : 0;
                 $this->owner->setAttribute($this->sortAttribute, $to);
             }
             break;
         case self::OPERATION_INSERT_BEFORE:
             $this->checkNode(true);
             $item = $this->owner->getAttribute($this->itemAttribute);
             if ($item !== null) {
                 $path = $this->getParentPath($this->node->getAttribute($this->pathAttribute));
                 $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item);
             }
             $this->owner->setAttribute($this->depthAttribute, $this->node->getAttribute($this->depthAttribute));
             if ($this->sortAttribute !== null) {
                 $this->moveTo($this->node->getAttribute($this->sortAttribute) - 1, false);
             }
             break;
         case self::OPERATION_INSERT_AFTER:
             $this->checkNode(true);
             $item = $this->owner->getAttribute($this->itemAttribute);
             if ($item !== null) {
                 $path = $this->getParentPath($this->node->getAttribute($this->pathAttribute));
                 $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item);
             }
             $this->owner->setAttribute($this->depthAttribute, $this->node->getAttribute($this->depthAttribute));
             if ($this->sortAttribute !== null) {
                 $this->moveTo($this->node->getAttribute($this->sortAttribute) + 1, true);
             }
             break;
         default:
             if ($this->owner->getIsNewRecord()) {
                 throw new NotSupportedException('Method "' . $this->owner->className() . '::insert" is not supported for inserting new nodes.');
             }
             $item = $this->owner->getAttribute($this->itemAttribute);
             $path = $this->getParentPath($this->owner->getAttribute($this->pathAttribute));
             $this->owner->setAttribute($this->pathAttribute, $path . $this->delimiter . $item);
     }
 }
開發者ID:arogachev,項目名稱:yii2-materialized-path,代碼行數:78,代碼來源:MaterializedPathBehavior.php

示例7: chainSave

 /**
  * @param ActiveRecord $model
  * @return ActiveRecord
  * @throws \yii\web\ServerErrorHttpException
  */
 protected function chainSave($model)
 {
     $model->scenario = $this->saveScenario;
     $model->attributes = Yii::$app->getRequest()->post();
     if (!$model->save()) {
         if (YII_DEBUG) {
             Yii::$app->response->statusCode = 500;
             Yii::$app->response->format = Response::FORMAT_JSON;
             var_dump($model->getErrors());
             Yii::$app->end();
         }
         throw new ServerErrorHttpException('Do not able to save the model.');
     }
     $model->refresh();
     return $model;
 }
開發者ID:laojiu,項目名稱:yii2-rest,代碼行數:21,代碼來源:RestAction.php


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