Answer the question
In order to leave comments, you need to log in
How to create a model in Yii, focusing on the given parameters?
The task is this:
There are table parameters in the database (their names, column names in them), written in this form
// ...
'params'=>array(
'tbl_profiles'=>array(
'tbl_name'=>'accounts',
'tbl_fields'=>array(
'username'=>'nickname',
'password'=>'key',
// ...
)
)
)
// ....
class Profiles extends CActiveRecord {
extract(Yii::app()->params[tbl_profiles][tbl_fields]);
public // что тут?
public // и тут?
// ...
public function tableName() {
return Yii::app()->params[tbl_profiles][tbl_name];
}
}
Answer the question
In order to leave comments, you need to log in
You do not need to describe the structure of the table in ActiveRecord, access to the table fields in it is carried out through magic methods based on the use of table metadata.
You are just saying this model is associated with a table and $model->column = $value; will immediately work if the table has a column field.
Try to generate a model using Gii and create your own model in the same way.
I recently did EAV proxying in CModel and did some further validation. The implementation is simple, there is a class inherited from CModel, there is protected $data = array(), in the constructor we write data to our property and write magic __get and __set that will work with $data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question