Download the PHP package blumster/yii2-model-based-controller without Composer
On this page you can find all versions of the php package blumster/yii2-model-based-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download blumster/yii2-model-based-controller
More information about blumster/yii2-model-based-controller
Files in blumster/yii2-model-based-controller
Package yii2-model-based-controller
Short Description Base model controller, which automatically loads an ActiveRecord before every call.
License BSD-3-Clause
Informations about the package yii2-model-based-controller
Model Based Controller for Yii2
A base controller, which loads an ActiveRecord before every action is ran. (Except, if there is a load exception.)
If you are managing an ActiveRecord class (for this example, a Company), this base controller will load the Company from the database, so it is already available for every action.
You can specify actions, where the ActiveRecord will not be loaded or loading it will be optional. If there is no exception for an action, and the controller couldn't load the model, the controller calls the
function, which you can override, and redirect, load a company another way or just display an error message. $error can be BaseModelController::ERROR_NO_PARAMETER (no parameter, or null) or BaseModelController::ERROR_NOT_FOUND (not found in the ddatabase)
Returning false will give an empty page, true will let framework to continue or
will redirect the invalid request.
You can also specify with or joinWith statements, which is automatically handled by the controller. Use BaseModelController::RELATION_WITH, if you don't want to add a condition. If you want to, add the condition in the modelLoadQuery($action) (like below) and use BaseModelController::RELATION_JOIN_WITH.
Loading the model will setup the ModelUrl class, which is a helper class for creating URLs. You can use the ModelUrl to automatically include the id of the loaded model.
is equal to
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: After install, you can start using it. Example code: