binkabir
(Binkabir)
1
Hello once again.
Can I do this is Yii?
creating a model that do not have a predefined table name but can give the table when creating an instances of it
eg.
<?php
class myModelName extends CActiveRecord{
protected $_tableName=null;
public function __construct($table){
$this->_tableName = $table
}
public function tableName()
{
return $this->_tableName;
}
}
?>
calling my Model in a controller class
<?php
$table = ‘chemistry’;
$model = new myModelName($table);
?>
so that i can use only this Model to have access to a hundred tables that have the same db structure ?
thanks once again.
zaccaria
(Matteo Falsitta)
2
Yes of corse is possible.
I did it for tables named like "note_2008", "note_2009", "note_2010".
You have just, like you correctly did, to edit ‘tableName()’
binkabir
(Binkabir)
3
this is what I did but it didn’t work
<?php
class Subject extends CActiveRecord {
public function __construct($subject){
$this->subject = $subject;
}
public function tableName(){
return $this->subject;
}
?>
this gave me error in the view page
how should i do it?
binkabir
(Binkabir)
5
thanks it worked, just some error from my part