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


PHP ActiveRecord::find方法代码示例

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


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

示例1: search

 public function search($params)
 {
     /* @var $query \yii\db\ActiveQuery */
     $query = $this->baseModel->find();
     $table_inheritance_joined = false;
     $dataProvider = new ActiveDataProvider(['query' => &$query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     if (!$this->load($params)) {
         return $dataProvider;
     }
     $object = Object::getForClass($this->baseModel->className());
     $baseModelTableName = $this->baseModel->tableName();
     $eavJoinsCount = 0;
     $osvJoinsCount = 0;
     foreach ($this->propertyGroups as $groupId => $properties) {
         foreach ($properties as $key => $propertyValue) {
             /** @var \app\properties\PropertyValue $propertyValue */
             $prop = Property::findById($propertyValue->property_id);
             if (empty($this->{$prop->key}) === true && $this->{$prop->key} !== '0') {
                 continue;
             }
             // determine property storage type and join needed table if needed
             if ($prop->is_column_type_stored) {
                 if ($table_inheritance_joined === false) {
                     $table_inheritance_joined = true;
                     $query->join('INNER JOIN', $object->column_properties_table_name . ' ti', 'ti.object_model_id = ' . $baseModelTableName . '.id');
                 }
                 if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
                     $query->andFilterWhere(['like', 'ti.' . $prop->key, $this->{$prop->key}]);
                 } else {
                     $query->andFilterWhere(['ti.' . $prop->key => $this->{$prop->key}]);
                 }
             } elseif ($prop->is_eav) {
                 $eavJoinsCount++;
                 $eavTableName = 'eav' . $eavJoinsCount;
                 $key = 'key' . $eavJoinsCount;
                 $query->join('INNER JOIN', "{$object->eav_table_name} {$eavTableName}", $eavTableName . '.object_model_id = ' . $baseModelTableName . ".id AND {$eavTableName}.key=:{$key}", [$key => $prop->key]);
                 if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) {
                     $query->andFilterWhere(['like', $eavTableName . '.value', $this->{$prop->key}]);
                 } else {
                     // numeric - direct match
                     $query->andFilterWhere([$eavTableName . '.value' => $this->{$prop->key}]);
                 }
             } elseif ($prop->has_static_values) {
                 $osvJoinsCount++;
                 $osvTableName = 'osv' . $osvJoinsCount;
                 $query->join('INNER JOIN', "object_static_values {$osvTableName}", "{$osvTableName}.object_id={$object->id} AND {$osvTableName}.object_model_id={$baseModelTableName}.id");
                 // numeric - direct match
                 $query->andFilterWhere(["{$osvTableName}.property_static_value_id", $this->{$prop->key}]);
             }
         }
     }
     return $dataProvider;
 }
开发者ID:yii2ApplicationCollect,项目名称:dotplant2,代码行数:53,代码来源:DynamicSearchModel.php

示例2: find

 public static function find()
 {
     if (array_key_exists('deleted', static::getTableSchema()->columns)) {
         return parent::find()->onCondition(static::tableName() . '.deleted = 0');
     } else {
         return parent::find();
     }
 }
开发者ID:dersonsena,项目名称:yii2-common-classes,代码行数:8,代码来源:ModelBase.php

示例3: find

 public static function find()
 {
     $user_id = Yii::$app->user->id;
     $find = parent::find();
     $find->andWhere('user_id=:user_id', [':user_id' => $user_id]);
     //        $find->andFilterWhere(['=', 'user_id', $user_id]);
     return $find;
 }
开发者ID:kd-brinex,项目名称:paruram,代码行数:8,代码来源:Frends.php

示例4: find

 public static function find()
 {
     $return = parent::find();
     if (in_array('deleted_at', parent::attributes())) {
         $tableName = static::getTableSchema()->name;
         $return->andWhere([$tableName . '.deleted_at' => null]);
     }
     return $return;
 }
开发者ID:elitedivision,项目名称:amos-core,代码行数:9,代码来源:Record.php

示例5: getItems

 public static function getItems()
 {
     $items = [];
     $models = parent::find()->all();
     foreach ($models as $model) {
         $items[] = ['label' => $model->title, 'url' => $model->slug];
     }
     return $items;
 }
开发者ID:hogvarce,项目名称:cms,代码行数:9,代码来源:Pages.php

示例6: find

 public static function find()
 {
     $city_id = Yii::$app->request->cookies['city'];
     $p['store_id'] = 109;
     $query = parent::find();
     //        $query->where('(store_id=:store_id) and not(title is null) and (value_char != \'\')',$p);
     $query->where('(store_id=:store_id)', $p);
     return $query;
 }
开发者ID:kd-brinex,项目名称:kd,代码行数:9,代码来源:Tovar.php

示例7: find

 public static function find($onlyDeleted = null)
 {
     if (is_null($onlyDeleted)) {
         return parent::find()->where([self::tableName() . '.delete' => 0]);
     } elseif ($onlyDeleted === true) {
         return parent::find()->where([self::tableName() . '.delete' => 1]);
     } elseif ($onlyDeleted === false) {
         return parent::find();
     }
 }
开发者ID:ailingsen,项目名称:betterdebt,代码行数:10,代码来源:BaseModel.php

示例8: getPoints

 public static function getPoints()
 {
     $points = parent::find()->all();
     if (count($points) > 0) {
         $geoObject = ['type' => 'FeatureCollection'];
         foreach ($points as $point) {
             $geoObject['features'][] = ['type' => 'Feature', 'id' => $point->id, 'geometry' => ['type' => 'Point', 'coordinates' => explode(',', $point->point)], 'properties' => ['balloonContent' => $point->body, 'iconContent' => $point->title], 'options' => ['preset' => $point->preset]];
         }
     } else {
         $geoObject = false;
     }
     return $geoObject;
 }
开发者ID:promo-pr,项目名称:cms,代码行数:13,代码来源:Map.php

示例9: find

 public static function find()
 {
     $tenantTableName = '{{%tenant}}';
     $field = '';
     $model = parent::find();
     if (parent::tableName() == $tenantTableName) {
         $field = '.id';
     } else {
         $field = '.tenant_id';
     }
     $model->where([parent::tableName() . $field => Yii::$app->session['tenant']]);
     return $model;
 }
开发者ID:antonio74,项目名称:daduu42,代码行数:13,代码来源:TenantActiveRecord.php

示例10: find

 public static function find($tables = null)
 {
     $aWhere = [];
     if ($tables) {
         if (!is_array($tables)) {
             $tables = [$tables];
         }
         foreach ($tables as $table) {
             $aWhere[$table . '.disabled'] = self::STATUS_ENABLE;
         }
         return parent::find()->where($aWhere);
     }
     return parent::find()->where(['disabled' => self::STATUS_ENABLE]);
 }
开发者ID:maildownload1985,项目名称:codeCenterA,代码行数:14,代码来源:CeActivieRecord.php

示例11: searchQuery

 /**
  * @param ActiveRecord $model
  * @param array $opts
  * @return ActiveQuery | array
  */
 static function searchQuery($model, $opts = [])
 {
     $opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts);
     $columns = $opts['columns'];
     $filters = $opts['filters'];
     $data = $opts['data'];
     if (null === $data) {
         $data = \Yii::$app->request->get();
     }
     $query = $opts['query'];
     if (is_string($query)) {
         $query = call_user_func([$model, $opts['query']]);
     } elseif (null === $query) {
         $query = $model->find();
         foreach (array_filter($model->getAttributes()) as $prop => $val) {
             $query->andWhere([$prop => $val]);
         }
     }
     if ($model->load($data) && $model->validate()) {
         foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) {
             if ($model->isAttributeChanged($name)) {
                 $attributeTypes = [];
                 if (method_exists($model, 'attributeTypes')) {
                     $attributeTypes = $model->attributeTypes();
                 }
                 $type = null;
                 if (isset($attributeTypes[$name])) {
                     $type = $attributeTypes[$name];
                 }
                 // Default filter function
                 $filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) {
                     /**
                      * @var string $name
                      * @var string|array $value
                      * @var string $type
                      */
                     $query->andFilterWhere(static::searchAttribute($name, $value, $type));
                 };
                 if (isset($columns[$name])) {
                     $name = $columns[$name];
                 }
                 call_user_func($filterFunc, $query, $name, $value, $type);
             }
         }
     }
     return $query;
 }
开发者ID:goodizer,项目名称:yii2-helpers,代码行数:52,代码来源:GridSearchHelper.php

示例12: find

 /**
  * Default sort on find command.
  *
  * @return ActiveQuery
  */
 public static function find()
 {
     return parent::find()->orderBy(['sort_index' => SORT_ASC]);
 }
开发者ID:luyadev,项目名称:luya-module-cms,代码行数:9,代码来源:NavItemPageBlockItem.php

示例13: findNonDeleted

 public static function findNonDeleted($param)
 {
     return parent::find()->where(['and', ['deleted' => false], $param]);
 }
开发者ID:releaznl,项目名称:releaz-project-manager,代码行数:4,代码来源:ReleazActiveRecord.php

示例14: find

 public static function find()
 {
     return parent::find()->with('type');
 }
开发者ID:Bochozkar,项目名称:stat.ink,代码行数:4,代码来源:DeathReason.php

示例15: find

 /**
  * @inherit
  */
 public static function find()
 {
     return parent::find()->where(['status' => self::STATUS_ACTIVE, 'type' => static::TYPE]);
 }
开发者ID:rocketyang,项目名称:huajuan,代码行数:7,代码来源:Meta.php


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