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


PHP ActiveRecord::getAttribute方法代碼示例

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


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

示例1: moveNode

 /**
  * @param int $to
  * @param int $depth
  * @throws Exception
  */
 protected function moveNode($to, $depth = 0)
 {
     $left = $this->owner->getAttribute($this->leftAttribute);
     $right = $this->owner->getAttribute($this->rightAttribute);
     $depth = $this->owner->getAttribute($this->depthAttribute) - $this->node->getAttribute($this->depthAttribute) - $depth;
     if ($this->treeAttribute === null || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) {
         // same root
         $this->owner->updateAll([$this->depthAttribute => new Expression("-[[{$this->depthAttribute}]]" . sprintf('%+d', $depth))], $this->getDescendants(null, true)->where);
         $delta = $right - $left + 1;
         if ($left >= $to) {
             $this->shift($to, $left - 1, $delta);
             $delta = $to - $left;
         } else {
             $this->shift($right + 1, $to, -$delta);
             $delta = $to - $right;
         }
         $this->owner->updateAll([$this->leftAttribute => new Expression("[[{$this->leftAttribute}]]" . sprintf('%+d', $delta)), $this->rightAttribute => new Expression("[[{$this->rightAttribute}]]" . sprintf('%+d', $delta)), $this->depthAttribute => new Expression("-[[{$this->depthAttribute}]]")], ['and', $this->getDescendants(null, true)->where, ['<', $this->depthAttribute, 0]]);
     } else {
         // move from other root
         $tree = $this->node->getAttribute($this->treeAttribute);
         $this->shift($to, null, $right - $left + 1, $tree);
         $delta = $to - $left;
         $this->owner->updateAll([$this->leftAttribute => new Expression("[[{$this->leftAttribute}]]" . sprintf('%+d', $delta)), $this->rightAttribute => new Expression("[[{$this->rightAttribute}]]" . sprintf('%+d', $delta)), $this->depthAttribute => new Expression("[[{$this->depthAttribute}]]" . sprintf('%+d', -$depth)), $this->treeAttribute => $tree], $this->getDescendants(null, true)->where);
         $this->shift($right + 1, null, $left - $right - 1);
     }
 }
開發者ID:nuclearman,項目名稱:yii2-nested-sets-1,代碼行數:31,代碼來源:NestedSetsBehavior.php

示例2: moveTo

 /**
  * @param int $to
  * @param bool $forward
  */
 protected function moveTo($to, $forward)
 {
     $this->owner->setAttribute($this->sortAttribute, $to);
     $tableName = $this->owner->tableName();
     $path = $this->getParentPath($this->node->getAttribute($this->pathAttribute));
     $like = strtr($path . $this->delimiter, ['%' => '\\%', '_' => '\\_', '\\' => '\\\\']);
     $unallocated = (new Query())->select("{$tableName}.[[{$this->sortAttribute}]]")->from("{$tableName}")->leftJoin("{$tableName} n", ['and', ['like', "n.[[{$this->pathAttribute}]]", $like . '%', false], ["n.[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute), "n.[[{$this->sortAttribute}]]" => new Expression("{$tableName}.[[{$this->sortAttribute}]] " . ($forward ? '+' : '-') . " 1")]])->where(['and', ['like', "{$tableName}.[[{$this->pathAttribute}]]", $like . '%', false], [$forward ? '>=' : '<=', "{$tableName}.[[{$this->sortAttribute}]]", $to], ["{$tableName}.[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute), "n.[[{$this->sortAttribute}]]" => null]])->orderBy(["{$tableName}.[[{$this->sortAttribute}]]" => $forward ? SORT_ASC : SORT_DESC])->limit(1)->scalar($this->owner->getDb());
     $this->owner->updateAll([$this->sortAttribute => new Expression("[[{$this->sortAttribute}]] " . ($forward ? '+' : '-') . " 1")], ['and', ['like', "[[{$this->pathAttribute}]]", $like . '%', false], ["[[{$this->depthAttribute}]]" => $this->node->getAttribute($this->depthAttribute)], ['between', $this->sortAttribute, $forward ? $to : $unallocated, $forward ? $unallocated : $to]]);
 }
開發者ID:arogachev,項目名稱:yii2-materialized-path,代碼行數:13,代碼來源:MaterializedPathBehavior.php

示例3: afterFindSingle

 /**
  * @return void
  */
 public function afterFindSingle()
 {
     $file = array_map(function ($attribute) {
         return $this->owner->getAttribute($attribute);
     }, $this->fields());
     if (array_key_exists('path', $file) && $file['path']) {
         $this->owner->{$this->attribute} = $this->enrichFileData($file);
     }
 }
開發者ID:yiioverflow,項目名稱:yii2-file-kit,代碼行數:12,代碼來源:UploadBehavior.php

示例4: insertNearInternal

 /**
  * Insert operation internal handler
  * @param bool $forward
  * @throws Exception
  */
 protected function insertNearInternal($forward)
 {
     $this->checkNode(true);
     $this->owner->setAttribute($this->parentAttribute, $this->node->getAttribute($this->parentAttribute));
     if ($this->sortable !== false) {
         if ($forward) {
             $this->owner->moveAfter($this->node);
         } else {
             $this->owner->moveBefore($this->node);
         }
     }
 }
開發者ID:karsel,項目名稱:yii2-adjacency-list,代碼行數:17,代碼來源:AdjacencyListBehavior.php

示例5: findInsertAfterRange

 /**
  * @param int $left
  * @param int $right
  * @return array|null
  */
 protected function findInsertAfterRange(&$left, &$right)
 {
     $result = null;
     $left = $this->node->getAttribute($this->rightAttribute);
     $right = $this->getNodeBehavior()->getNext()->select($this->leftAttribute)->scalar();
     if ($right === false) {
         $result = $this->getNodeBehavior()->getParent()->select([$this->leftAttribute, $this->rightAttribute])->createCommand()->queryOne();
         $right = $result[$this->rightAttribute];
     }
     $right = (int) $right;
     return $result;
 }
開發者ID:paulzi,項目名稱:yii2-nested-intervals,代碼行數:17,代碼來源:NestedIntervalsBehavior.php

示例6: getSortableQuery

 /**
  * @return \yii\db\ActiveQuery
  */
 protected function getSortableQuery()
 {
     switch ($this->operation) {
         case self::OPERATION_PREPEND_TO:
         case self::OPERATION_APPEND_TO:
             $path = $this->node->getAttribute($this->pathAttribute);
             $depth = $this->node->getAttribute($this->depthAttribute) + 1;
             break;
         case self::OPERATION_INSERT_BEFORE:
         case self::OPERATION_INSERT_AFTER:
             $path = $this->node->getParentPath();
             $depth = $this->node->getAttribute($this->depthAttribute);
             break;
         default:
             $path = $this->getParentPath();
             $depth = $this->owner->getAttribute($this->depthAttribute);
     }
     $tableName = $this->owner->tableName();
     return $this->owner->find()->andWhere($this->treeCondition())->andWhere($path !== null ? ['like', "{$tableName}.[[{$this->pathAttribute}]]", $this->getLike($path), false] : '1=0')->andWhere(["{$tableName}.[[{$this->depthAttribute}]]" => $depth]);
 }
開發者ID:paulzi,項目名稱:yii2-materialized-path,代碼行數:23,代碼來源:MaterializedPathBehavior.php

示例7: moveNode

 /**
  * @param integer $value
  * @param integer $depth
  */
 protected function moveNode($value, $depth)
 {
     $db = $this->owner->getDb();
     $leftValue = $this->owner->getAttribute($this->leftAttribute);
     $rightValue = $this->owner->getAttribute($this->rightAttribute);
     $depthValue = $this->owner->getAttribute($this->depthAttribute);
     $depthAttribute = $db->quoteColumnName($this->depthAttribute);
     $depth = $this->node->getAttribute($this->depthAttribute) - $depthValue + $depth;
     if ($this->treeAttribute === false || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) {
         $delta = $rightValue - $leftValue + 1;
         $this->shiftLeftRightAttribute($value, $delta);
         if ($leftValue >= $value) {
             $leftValue += $delta;
             $rightValue += $delta;
         }
         $condition = ['and', ['>=', $this->leftAttribute, $leftValue], ['<=', $this->rightAttribute, $rightValue]];
         $this->applyTreeAttributeCondition($condition);
         $this->owner->updateAll([$this->depthAttribute => new Expression($depthAttribute . sprintf('%+d', $depth))], $condition);
         foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) {
             $condition = ['and', ['>=', $attribute, $leftValue], ['<=', $attribute, $rightValue]];
             $this->applyTreeAttributeCondition($condition);
             $this->owner->updateAll([$attribute => new Expression($db->quoteColumnName($attribute) . sprintf('%+d', $value - $leftValue))], $condition);
         }
         $this->shiftLeftRightAttribute($rightValue + 1, -$delta);
     } else {
         $leftAttribute = $db->quoteColumnName($this->leftAttribute);
         $rightAttribute = $db->quoteColumnName($this->rightAttribute);
         $nodeRootValue = $this->node->getAttribute($this->treeAttribute);
         foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) {
             $this->owner->updateAll([$attribute => new Expression($db->quoteColumnName($attribute) . sprintf('%+d', $rightValue - $leftValue + 1))], ['and', ['>=', $attribute, $value], [$this->treeAttribute => $nodeRootValue]]);
         }
         $delta = $value - $leftValue;
         $this->owner->updateAll([$this->leftAttribute => new Expression($leftAttribute . sprintf('%+d', $delta)), $this->rightAttribute => new Expression($rightAttribute . sprintf('%+d', $delta)), $this->depthAttribute => new Expression($depthAttribute . sprintf('%+d', $depth)), $this->treeAttribute => $nodeRootValue], ['and', ['>=', $this->leftAttribute, $leftValue], ['<=', $this->rightAttribute, $rightValue], [$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute)]]);
         $this->shiftLeftRightAttribute($rightValue + 1, $leftValue - $rightValue - 1);
     }
 }
開發者ID:phpsong,項目名稱:yii2song,代碼行數:40,代碼來源:NestedSetsBehavior.php

示例8: compareValue

 /**
  * @inheritDoc
  */
 public function compareValue(ActiveRecord $model, $value)
 {
     /** @var ActiveRecord $model */
     return $model->getAttribute($this->attributeName) == $value;
 }
開發者ID:nanodesu88,項目名稱:easyii,代碼行數:8,代碼來源:ActiveDataColumn.php

示例9: editAttribute

 /**
  * @param ActiveRecord $model
  * @return string
  */
 public function editAttribute($model, $field, $params = [])
 {
     if (!isset($params['options'])) {
         $params['options'] = [];
     }
     $options = $params['options'];
     unset($params['options']);
     /** @var \yii\widgets\ActiveField $form */
     $form = $params['formField'];
     unset($params['formField']);
     $return = $form->fileInput($options);
     $file = $model->getAttribute($field->varname);
     if ($file) {
         $return .= "<div class='form-group'><fieldset>";
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $root = Yii::getAlias('@webroot/' . $file);
         $type = explode("/", finfo_file($finfo, $root));
         $return .= Html::activeCheckBox($model, '[uwfdel]' . $field->varname, ['label' => Module::t('Delete file')]) . "<br>";
         if ($type[0] == 'image') {
             $return .= Html::img(Url::base() . "/" . $file, ['class' => 'UWfile-image-preview']);
         } else {
             $assetsPath = Yii::$app->assetManager->getBundle('marsoltys\\yii2user\\assets\\UserAssets')->basePath;
             $assetsUrl = Yii::$app->assetManager->getBundle('marsoltys\\yii2user\\assets\\UserAssets')->baseUrl;
             $img = "/img/" . pathinfo($file, PATHINFO_EXTENSION) . ".png";
             if (file_exists($assetsPath . $img)) {
                 $return .= Html::img($assetsUrl . $img, ['class' => 'UWfile-image-preview']);
             } else {
                 $return .= Html::img($assetsUrl . "/img/file.png", ['class' => 'UWfile-image-preview']);
             }
             $return .= pathinfo($file, PATHINFO_BASENAME) . " ";
             $return .= Html::a(pathinfo($file, PATHINFO_BASENAME) . " ", Url::base() . "/" . $file);
         }
         $return .= "</fieldset></div>";
     }
     return $return;
 }
開發者ID:marsoltys,項目名稱:yii2user,代碼行數:40,代碼來源:UWfile.php

示例10: getNode

 /**
  * @param ActiveRecord|TreeInterface $node
  * @return array
  */
 protected function getNode($node)
 {
     $items = [];
     /** @var ActiveRecord[]|TreeInterface[] $children */
     $children = $node->children;
     foreach ($children as $n => $node) {
         $items[$n]['id'] = $node->getPrimaryKey();
         $items[$n]['name'] = $node->getAttribute($this->nameAttribute);
         $items[$n]['children'] = $this->getNode($node);
         $items[$n]['update-url'] = Url::to([$this->advancedUpdateRoute, 'id' => $node->getPrimaryKey()]);
     }
     return $items;
 }
開發者ID:voskobovich,項目名稱:yii2-tree-manager,代碼行數:17,代碼來源:Nestable.php

示例11: WhereConstruct

 /**
  * Формирует массив конструкции Where() ActiveQuery.
  * @param ActiveRecord $ModelSearch Модель, для который создаем конструкцию Where().
  * @param string $Field Атрибут модели, по которому осуществляем поиск, фильтрацию.
  * @param integer $Type Тип значения в атрибуте модели (Proc::Time, Proc::Date, Proc::DateTime).
  * @return array Массив конструкции Where().
  */
 static function WhereConstruct($ModelSearch, $Field, $Type = 0)
 {
     $AttributeModelValue = $ModelSearch->getAttribute($Field);
     $AttributeValue = empty($AttributeModelValue) ? $ModelSearch->{$Field} : $ModelSearch->getAttribute($Field);
     preg_match('/(>=|<=|>|<|=)?(.*)/', $AttributeValue, $Matches);
     $Operator = $Matches[1];
     $Value = $Matches[2];
     if (!empty($Value)) {
         switch ($Type) {
             case self::Time:
                 $Value = date("H:i:s", strtotime($Value));
                 break;
             case self::Date:
                 $Value = date("Y-m-d", strtotime($Value));
                 break;
             case self::DateTime:
                 $Value = date("Y-m-d H:i:s", strtotime($Value));
                 break;
         }
     }
     return [empty($Operator) ? '=' : $Operator, $Field, $Value];
 }
開發者ID:vovancho,項目名稱:yii2test,代碼行數:29,代碼來源:Proc.php

示例12: deleteTranslation

 /**
  * @param \yii\db\ActiveRecord $model
  * @return bool
  */
 private function deleteTranslation($model)
 {
     if (!$model->isNewRecord) {
         $model->delete();
         unset($this->_models[$model->getAttribute($this->languageAttribute)]);
     }
     return true;
 }
開發者ID:maddoger,項目名稱:yii2-core,代碼行數:12,代碼來源:TranslatableBehavior.php

示例13: getValue

 /**
  * @return int
  */
 public function getValue()
 {
     return $this->owner->getAttribute($this->attributeName);
 }
開發者ID:nanodesu88,項目名稱:yii2-activerecord-sort,代碼行數:7,代碼來源:SortBehavior.php

示例14: getAttribute

 public function getAttribute($name)
 {
     return isset($this->{$name}) ? $this->{$name} : parent::getAttribute($name);
 }
開發者ID:noikiy,項目名稱:wowewe,代碼行數:4,代碼來源:MWxAction.php

示例15: getAttribute

 /**
  * Returns the named attribute value.
  * If this record is the result of a query and the attribute is not loaded,
  * null will be returned.
  * @param string $name the attribute name
  * @return mixed the attribute value. Null if the attribute is not set or does not exist.
  * @see hasAttribute()
  */
 public function getAttribute($name)
 {
     if ($this->hasAttribute($name)) {
         // we will now have optionally applied default values if this is a new record
         return parent::getAttribute($name);
     }
     return null;
 }
開發者ID:fangface,項目名稱:yii2-concord,代碼行數:16,代碼來源:ActiveRecord.php


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