jzfpost / yii2-dynamicfinder
Dynamic finder trait for Yii2-framework
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: >=2.0.4
This package is not auto-updated.
Last update: 2024-06-01 03:46:50 UTC
README
Dynamic finder trait for Yii2-framework ActiveRecord models
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist jzfpost/yii2-dynamicfinder "*"
or add
"jzfpost/yii2-dynamicfinder": "*"
to the require section of your composer.json
file.
Usage
Model
use jzfpost\dynamicfinder\DynamicFinderTrait; class Customer extends \yii\db\ActiveRecord { use DynamicFinderTrait; your code... }
Controller
$model = Customer::findOneByEmail($email); // return Customer::find()->where(['email' => $email])->one(); $customers = Customer::findAllByEmail($email); // return Customer::find()->where(['email' => $email])->all(); $count = Customer::findCountByEmail($email); // return Customer::find()->where(['email' => $email])->count(); $username = Customer::findUsernameByEmail($email); // return username value where email=$email; $updatedAt = Customer::findUpdatedAtByEmailOrUsername($email, $username); // return updated_at value where email=$email or username = $username; $createdAt = Customer::findCreatedAtByEmailAndUsername($email, $username); // return created_at value where email=$email and username = $username; $customers = Customer::findByEmail($email) equivalently Customer::findAllByEmail($email);
Syntax
findBy<Field>(field_value)
find<Select>By<Field>(field_value)
find<Select>By<Field1>And<Field2>(field_value1, field_value2)
find<Select>By<Field1>Or<Field2>(field_value1, field_value2)
where:
'Select' may by 'All', 'One', 'Count' or one of model attribute. If 'Select' not set, by default return 'All'.
'Field' is model attribute on where condition.