2017 © Pedro Peláez
 

yii2-extension yii2-active-take

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

image

bigdropinc/yii2-active-take

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  • Tuesday, May 16, 2017
  • by tv88dn
  • Repository
  • 1 Watchers
  • 0 Stars
  • 53 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

Active Take

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found, not saved or validation failed, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist bigdropinc/yii2-active-take "*"

or add, (*4)

"bigdropinc/yii2-active-take": "*"

to the require section of your composer.json file., (*5)

Usage

Please, try to remember how many times you make compare like this, (*6)

if(User::findOne($id) !== null){

}

Or something like this, (*7)

if($model->save()){

}

OOP best practice said that method should not return null. Much better raise an exception. But in many cases we really need to get null value without raising exceptions. But in many cases no... This extension brings you opportunity to raise and process ActiveRecordExceptions during the interaction with ActiveRecord methods in very simple way. It's can make your code much more simple, clear and readable. It will allowed you to remove ugly and routine compare with null., (*8)

Active Record

By using bigdropinc\take\ActiveRecordTrait into your ActiveRecord class you got this features: * all method "find" methods will get the pair "take" method (findOne - takeOne, findAll - takeAll). If find method returns empty result, take method will raise an RecordNotFoundException * method validateOrFail will raise RecordInvalidException if validate returns false * method saveOrFail will raise RecordInvalidException if model has validation errors during save. Also saveOrFail will raise RecordNotSavedException if model validations was passed but model saving returned false, (*9)

Active Query

By using bigdropinc\take\ActiveRecordTrait into your ActiveRecord class you got this features: * method takeOne will behaves like method one but raise an RecordNotFoundException if nothing found * method takeAll will behaves like method all but raise an RecordNotFoundException if nothing found, (*10)

Error Handler

To render 404 page while RecordNotFoundException was raising, you should modify your main config file:, (*11)

'components' => [
        'errorHandler' => [
            'class' => 'bigdropinc\take\ErrorHandler'
        ],
    ],

The Versions

16/05 2017

dev-master

9999999-dev

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  Sources   Download

BSD-3-Clause

The Requires

 

by Vadim Trunov

extension yii2 exception activerecord take takeone takeall activequery recordnotfound

16/05 2017

v1.2.1

1.2.1.0

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  Sources   Download

BSD-3-Clause

The Requires

 

by Vadim Trunov

extension yii2 exception activerecord take takeone takeall activequery recordnotfound

16/05 2017

v1.2

1.2.0.0

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  Sources   Download

BSD-3-Clause

The Requires

 

by Vadim Trunov

extension yii2 exception activerecord take takeone takeall activequery recordnotfound

10/05 2017

v1.1

1.1.0.0

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  Sources   Download

BSD-3-Clause

The Requires

 

by Vadim Trunov

extension yii2 exception activerecord take takeone takeall activequery recordnotfound

10/05 2017

v1.0

1.0.0.0

Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found

  Sources   Download

BSD-3-Clause

The Requires

 

by Vadim Trunov

extension yii2 exception activerecord take takeone takeall activequery recordnotfound