Download the PHP package bigdropinc/yii2-active-take without Composer
On this page you can find all versions of the php package bigdropinc/yii2-active-take. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bigdropinc/yii2-active-take
More information about bigdropinc/yii2-active-take
Files in bigdropinc/yii2-active-take
Package yii2-active-take
Short Description Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found
License BSD-3-Clause
Informations about the package yii2-active-take
Active Take
Provides your ActiveRecords and ActiveQuery with mechanism of raising error when record not found, not saved or validation failed
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
Please, try to remember how many times you make compare like this
Or something like this
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.
Active Record
By using 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
- method validateOrFail will raise if validate returns false
- method saveOrFail will raise if model has validation errors during save. Also saveOrFail will raise if model validations was passed but model saving returned false
Active Query
By using into your ActiveRecord class you got this features:
- method takeOne will behaves like method one but raise an if nothing found
- method takeAll will behaves like method all but raise an if nothing found
Error Handler
To render 404 page while was raising, you should modify your main config file: