PHP code example of phpshko / yii2-magic-scopes
1. Go to this page and download the library: Download phpshko/yii2-magic-scopes library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpshko / yii2-magic-scopes example snippets
* @method ActiveQuery|UserWithMagic orAddressIdNotLike($addressId)
* @method ActiveQuery|UserWithMagic orAddressIdNotBetween($from, $to)
* @method ActiveQuery|UserWithMagic orAddressIdNotMore($than, $ctiveRecord
{
/**
* @inheritdoc
* @return MagicActiveQuery|UserWithMagic
*/
public static function find()
{
return new MagicActiveQuery(get_called_class());
}
/**
* This is the model class for table "user".
*
* @property integer $id
* @property string $username
* @property string $forename
* @property string $surname
* @property integer $year
* @property integer $address_id
*/
class UserWithCreate extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
* @return UserWithCreateQuery|UserWithCreate
*/
public static function find()
{
return new UserWithCreateQuery(get_called_class());
}
...
* @method UserWithCreateQuery|UserWithCreate orAddressIdNot($addressId)
* @method UserWithCreateQuery|UserWithCreate orAddressIdNotIn($array)
* @method UserWithCreateQuery|UserWithCreate orAddressIdNotLike($addressId)
* @method UserWithCreateQuery|UserWithCreate orAddressIdNotBetween($from, $to)
* @method UserWithCreateQuery|UserWithCreate orAddressIdNotMore($than, $lass' => \phpshko\magicscopes\MagicScopesBehavior::className()
]
];
}
}
...
* @method ActiveQuery|UserWithAttach orAddressIdNotIn($array)
* @method ActiveQuery|UserWithAttach orAddressIdNotLike($addressId)
* @method ActiveQuery|UserWithAttach orAddressIdNotBetween($from, $to)
* @method ActiveQuery|UserWithAttach orAddressIdNotMore($than, $|UserWithAttach
*/
public static function find()
{
$query = parent::find();
$query->attachBehavior('MagicScopesBehavior', MagicScopesBehavior::className());
return $query;
}
$queryWith = UserWith::find()
->andId(45)
->andUsernameLike('php')
->andYearBetween(1980, 2000)
->addressIdMore(10);
$queryWithout = UserWithout::find()
->andWhere(['id' => 45])
->andWhere(['like', 'username', 'php'])
->andWhere(['between', 'year', 1980, 2000])
->andWhere(['>', 'address_id', 10]);
UserWith::find()->id(5) == UserWith::find()->andId(5)
->id($id)
->idIn($array)
->idLike($id)
->idBetween($from, $to)
->idMore($than, $d)
->idNotBetween($from, $to)
->idNotMore($than, $, $otMore($than, $than, $false)
->orId($id)