当前位置: 首页>>代码示例>>PHP>>正文


PHP ActiveRecord::hasProperty方法代码示例

本文整理汇总了PHP中yii\db\ActiveRecord::hasProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::hasProperty方法的具体用法?PHP ActiveRecord::hasProperty怎么用?PHP ActiveRecord::hasProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::hasProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * @return string
  */
 public function run()
 {
     if ($this->model->hasProperty('mlConfig') and count($this->model->mlConfig['languages']) > 1) {
         return $this->render('index');
     } else {
         return $this->getInputField($this->attribute);
     }
 }
开发者ID:kuzmiand,项目名称:multilanguage,代码行数:11,代码来源:MultiLanguageActiveField.php

示例2: setRelation

 /**
  * Loads a specific relation with $data.
  * incremental: 		existing subitems are neither removed nor unlinked.
  * non-incremental:		existing (loaded) subitems are unlinked and/or deleted.
  * 
  * @param  ActiveRecord  $model 			model
  * @param  string        $relationName      the relation's name
  * @param  array         $data              data to load, including relational data
  * @param  array         $config            configuration array
  * @internal
  */
 private function setRelation(&$model, $relationName, &$data, &$config)
 {
     if (!$model->hasProperty($relationName)) {
         throw new \yii\base\UnknownPropertyException(sprintf('model {%s} has no relation {%s}', $model->className(), $relationName));
     }
     $relation =& $config[self::RELATIONS][$relationName];
     $formName = ArrayHelper::getValue($relation, self::FORMNAME, false);
     $scenario = ArrayHelper::getValue($relation, self::SCENARIO, $this->defaultScenario);
     $incremental = ArrayHelper::getValue($relation, self::INCREMENTAL, $this->defaultIncremental);
     $delete = ArrayHelper::getValue($relation, self::DELETE, $this->defaultDelete);
     $relationData = $formName == false ? $data : $data[$formName];
     $rel = $model->getRelation($relationName);
     $pattern = new $rel->modelClass();
     $recursive = !$pattern->hasMethod('isActiveDocument');
     $models = null;
     $relation[self::REMOVE] = [];
     $relation[self::LINK] = [];
     // relation is a collection or a single component
     if ($rel->multiple) {
         $models = [];
         if ($incremental) {
             // loop through array data and load sub models
             foreach ($relationData as $key => $value) {
                 $m = $this->loadModel($rel->modelClass, $scenario, $value, $relation, $recursive);
                 $models[] = $m;
             }
         } else {
             $sort = ArrayHelper::getValue($relation, self::SORTABLE, null);
             if ($sort !== null) {
                 $index = 0;
                 foreach ($relationData as $key => &$value) {
                     $relationData[$key][$sort] = $index++;
                 }
             }
             // loop through relation data, load data and detect removable sub models
             foreach ($model->{$relationName} as $item) {
                 $keys = $item->getPrimaryKey(true);
                 // try to find subitem in data
                 reset($relationData);
                 $found = false;
                 foreach ($relationData as $key => &$value) {
                     // normalize
                     if (!empty($formName)) {
                         $value = $value[$formName];
                     }
                     $modelKeys = array_intersect_key($value, $keys);
                     if (count(array_diff_assoc($modelKeys, $keys)) == 0) {
                         $m = $this->loadExistingModel($item, $scenario, $value, $relation, $recursive);
                         $models[] = $m;
                         $found = true;
                         // processed, so remove from data array
                         unset($relationData[$key]);
                         break;
                     }
                 }
                 // we have an existing item, but it was not loaded by $data, so mark for remove.
                 if (!$found) {
                     $relation[self::REMOVE][] = $item;
                 }
             }
             // everything left in $relationData is new model data
             // model might be existing, but not linked
             foreach ($relationData as $key => $value) {
                 // normalize
                 if (!empty($formName)) {
                     $value = $value[$formName];
                 }
                 $m = $this->loadModel($rel->modelClass, $scenario, $value, $relation, $recursive);
                 $models[] = $m;
                 $relation[self::LINK][$this->serializeKey($model)][] = $m;
             }
         }
     } else {
         // relation is a single component
         $oldItem = $model->{$relationName};
         $models = $this->loadModel($rel->modelClass, $scenario, $value, $relation, $recursive);
         if (!$incremental) {
             if ($oldItem !== null) {
                 $keys = $oldItem->getPrimaryKey(true);
                 if ($models !== null) {
                     $modelKeys = $models->getPrimaryKey(true);
                     if (count(array_diff_assoc($keys, $modelKeys)) !== 0) {
                         $relation[self::REMOVE][] = $oldItem;
                     }
                 } else {
                     $relation[self::REMOVE][] = $models;
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:e-frank,项目名称:yii2-data,代码行数:101,代码来源:ActiveDocumentBehavior.php


注:本文中的yii\db\ActiveRecord::hasProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。