Wednesday, July 22, 2015

Yii2 Notes

Entry script:
Usually index.php on web folder is entry script. We can change this name. All request to Yii site are executing via Entry Script only. So we can declare here any Constant, Aliases etc.. which are going to use via over all site.

Applications
Applications are objects that govern the overall structure and lifecycle of Yii application systems. Each Yii application system contains a single application object which is created in the entry script and is globally accessible through the expression \Yii::$app.

Application Components
They are the components OR libraries used by Application. Ex: URL Manager.

Aliases (@):
When we not know exact path or URL we can use @ symbol in starting of same, then Yii will search the path or URL through the site. We can also add aliases by manually.

@web will find web directory path of Yii.

Yii::setAlias('@foo', '/path/to/foo'); // Set aliases
Yii::getAlias('@foo/test/file.php');  // Get aliases: /path/to/foo/test/file.php


Class Auto loading:
Yii using PHP's auto loading concept. That is a class will auto load necessary classes when it trying to use them, so we not need to include the necessary class on top. The auto loader is installed when you include the Yii.php file. For this purpose we are using namespace at the top of classes, because namespace having the roots to all classes.

yii\base\Model taking care of form elements and
yii\db\ActiveRecord taking care of database activities.

The expression Yii::$app represents the application instance, which is a globally accessible singleton

Controllers
After Application initiate process Controller will analyze incoming request data, pass them to models, inject model results into views.

Models
Its making control between code and database. Model representing business data, rules and logic.
Attribute: Models represent business data(user inputs and model variables) in terms of attributes.
Attribute Labels: Label of inputs. Ex usage: $model->getAttributeLabel('name'); You may override label of inputs.
Massive Assignment: Assigning post values return back to form when validation fails.
Safe Attributes: Massive assignment only applies to the so-called safe attributes.
Unsafe Attributes: Will used on you may want to validate an attribute but do not want to mark it safe.
Data Exporting: Models often need to be exported in different formats. For example, you may want to convert a collection of models into JSON or Excel format.
Fields: By default, field names are equivalent to attribute names. But you can change it.

Models are the central places to represent business data, rules and logic. They often need to be reused in different places. In a well-designed application, models are usually much fatter than controllers.

Scenarios
A model may be used in different scenarios. For example, a User model may be used to collect user login inputs, but it may also be used for the user registration purpose. In different scenarios, a model may use different business rules and logic. For example, the email attribute may be required during user registration, but not so during user login.








Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS&l...