The ActiveRecord class in Yii provides an object oriented interface (aka ORM) for accessing database stored data. Similar structures can be found in most modern frameworks like Laravel, CodeIgniter, Smyfony and Ruby. Today, we’ll go over the implementation in Yii 2.0 and I’ll show you some of the more advanced features of it.
Model class intro
The Yii ActiveRecord is an advanced version of the base yii\base\Model
which is the foundation of the Model-View-Controller architecture. I’ll quickly explain the most important functionality that ActiveRecord inherits from the Model class:
Attributes
The business data is held in attributes. These are publicly available properties of the model instance.
All the attributes can conveniently be assigned massively by assigning any array to the attributes
property of a model. This works because the base Component class (the base of almost everything in Yii 2.0) implements the __set()
method which in turn calls the setAttributes()
method in the Model class. The same goes for retrieving; all attributes can be retrieved by getting the attributes
property. Again, built upon the Component class which implements __get()
which calls the getAttributes()
in the Model class.
Models also supply attribute labels which are used for display purposes which makes using them in forms on pages easier.
Continue reading %Yii 2.0 ActiveRecord Explained%
by Arno Slatius via SitePoint
No comments:
Post a Comment