本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例5: getItems
public static function getItems()
{
$items = [];
$models = parent::find()->all();
foreach ($models as $model) {
$items[] = ['label' => $model->title, 'url' => $model->slug];
}
return $items;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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]);
}
示例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;
}
示例12: find
/**
* Default sort on find command.
*
* @return ActiveQuery
*/
public static function find()
{
return parent::find()->orderBy(['sort_index' => SORT_ASC]);
}
示例13: findNonDeleted
public static function findNonDeleted($param)
{
return parent::find()->where(['and', ['deleted' => false], $param]);
}
示例14: find
public static function find()
{
return parent::find()->with('type');
}
示例15: find
/**
* @inherit
*/
public static function find()
{
return parent::find()->where(['status' => self::STATUS_ACTIVE, 'type' => static::TYPE]);
}