creating a clade model
Basically, models are classes that represents a certain object. Clade Models extends the ActiveRecord class. The ActiveRecord class contains finders and other methods to manage the database. Since Clade is an MVC Framework, we will then discuss the basics in creating a model. Models must be located under app/models/ directory. The filename of the model to be created must be also the class name of the model.
Now, let’s try creating a model called User. The following code is a template of a model class.
class User extends ActiveRecord{
public function __construct($post = ”)
{
$this->tablename = ‘users’;
$this->property = $post;
parent::__construct();
}
}
Now we’ll create a model called User. Create a class called User and extend ActiveRecord.
class User extends ActiveRecord{
Models have constructors that is executed when the model is instantiated. The method __construct is a reserved keyword in PHP5 that serves as a constructor of a class. A default argument post is optional and can be used to pass any variable when the model is instantiated.
public function __construct($post = ”)
Models are basically a representation of an object. We need to specify the name of the table that this object will interact with. This example interacts with the “users” table, we will then assign the name of the table that we are going to use to this variable.
$this->tablename = ‘users’;
The assignment below assigns all posted variables to class attribute “property” if POST variable is passed in to the constructor of this model.
$this->property = $post;
We will then call the constructor of this model which is the ActiveRecord class.
parent::__construct();
Now, we’re done creating a model.
Fatal error: Call to undefined function post_comments_feed_link() in /home/iyanski/public_html/devian/wp-content/themes/outdoorsy_fixed/single.php on line 11