Dear Friend
Here is one implementation of the above concept.
I have created a module person.
modules/person/PersonModule.php
<?php
class PersonModule extends CWebModule
{
public $table;
public function init()
{
$this->setImport(array(
'application.modules.person.models.*',
'application.components.person.components.*',
));
if(class_exists("Profile"))
Profile::$table=$this->table;
}
//below are the default things generated by GII
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
return true;
}
else
return false;
}
}
Now I am having
-
Model Profile == modules/person/models/Profile.php
-
Controller ProfileController == modules/person/models/ProfileController.php
3.views == modules/person/models/views/profile.
All the things are generated bi GII from a table person in database.
Table person was deleted after creating these files.
modules/person/models/Profile.php
class Profile extends CActiveRecord
{
public static $table;
public function tableName()
{
return self::$table;
}
//Rest of the contents of AR.........
In main.php I am instantiating the new applications in the follwing way.
'modules'=>array(
...................................................
...................................................
'student'=>array('class'=>'application.modules.person.PersonModule','table'=>'student'),
'teacher'=>array('class'=>'application.modules.person.PersonModule','table'=>'teacher'),
......................................................
......................................................
),
Now we have created two application student and teacher.
Now we can list,view ,update and delete actions in the following way.
index.php?r=student/profile/view&id=1
index.php?r=teacher/profile/create
index.php?r=teacher/profile/update&id=4
I think the only prerequsite here the structure of tables student and teacher should be same as person.
There is no need for the presence of a table with class name.
When ActiveRecord try to create metadata, it invokes AR::tablename() rather than using the classname.
Regards.