platx/yii2-active-record Extended ActiveRecord class for Yii2

activerecord

Yii2 Active Record

Extended ActiveRecord class for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist platx/yii2-active-record "*"

or add

"platx/yii2-active-record": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

class YourModel extends \platx\activerecord\ActiveRecord 
{
    public function rules()
    {
        return \yii\helpers\ArrayHelper::merge(parent::rules(), [
            // here put your validation rules
        ]);
    }
    public function behaviors()
    {
        return \yii\helpers\ArrayHelper::merge(parent::behaviors(), [
            // here put your behaviors configs
        ]);
    }
    protected function filterAttributes()
    {
        parent::filterAttributes();
        // Here you may filter different attributes in your model, like:
        $this->_mainQuery->andFilterWhere(['your_attribute' => $this->your_attribute]);
    }
}

For find record in DB by ID attribute, use this code:

$model = YourModel::findByPk($id);

where $id - integer, record ID.

If you want to know attribute has been modified or no, you can use following code:

$result = $model->isChanged('attribute_name');

where $model - object of your model class, attribute_name - name of model attribute for checking.

To get data as array for dropdown, radio or checkbox list, try this:

$dataArray = YourModel::listAll();

To get query with filtered attributes, use this code:

$query = $model->buildQuery();

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

No stable releases.

Comments



No stable releases.



MIT license
Stats
0 github stars & 0 github forks
0 downloads in the last day
5 downloads in the last 30 days
2150 total downloads