-
Notifications
You must be signed in to change notification settings - Fork 3
Model
A model is an instance of Xoops_Zend_Db_Model or a class that extends Xoops_Zend_Db_Model. The application's model class files are put in the models directory under the application root.
The class name of model is composed by application namespace, string Model and model name. For example, the model article of the application news is named as News_Model_Article
What you should do if you want create a model ? Basically nothing. The following code represent a model and is ready:
class News_Model_Article extends Xoops_Zend_Db_Model
{
}
The file name is article.php, case sensitive.
The model above to the table _{prefix}news_article is a one-to-one correspondence. if you want use an specific class name, the code above will be wrote as follow:
class News_Model_Article extends Xoops_Zend_Db_Model
{
protected $_name = 'you_specific_table'; //The table name will append Xoops database table name prefix.
}
More, if the primary key in the table is not id, you need a line as follow:
class News_Model_Article extends Xoops_Zend_Db_Model
{
protected $_primary = "the_id";
protected $_name = 'you_specific_table'; //The table name will append Xoops database table name prefix.
}
Writing a model class just extends Xoops_Zend_Db_Model seems a physical labour. In Xoops Engine, even the model file is not necessary. You can create a model without a real model file if the table name and primary key match the nomenclature.
// the file contains _News_Model_Article_ is not exist.
$model = new News_Model_Article();