Well in fact i don’t want to create and use new model instance from my class i want my class to be the model object
Let me explain more clearly
i have a class called BaseUser that extends CActiveRecord ( generate by gii )
class BaseUser extends CActiveRecord {
....
}
now i want to create My own model on top of this i call it User.
And i want to put all my logic methods inside this class
exemple
class User extends BaseUser {
// add some rules
public function rules()
{
$rules = array(
array('email', 'email'),
array('email, first_name, last_name, password, password_confirmation', 'required', 'on'=>'signup'),
);
return CMap::mergeArray( parent::rules(),$rules);
}
// put creation of user logic inside my model
public function createPowerUser(array $data)
{
// here i have complex process to handle
......
....
$this->user_type = POWER_USER;
$this->user_name = $data['user_name'];
// then i save
return $this->save();
}
public function getByEmail($email)
{
// this does not work !
$this->find('email=?',array($email);
}
public function notify()
{
Mailer::Send($this->email,'a message');
}
}
No i use my model in a controller
public function actionSignup()
{
$user = new User('signup');
if( true === $user->createPowerUser($_POST['user']) ) {
echo $user->id;
$user->notify();
}
}
By doing this no problem i can create my user and then access the properties after the creation
Now i want to be able to what i explain in my first post. because by using model static method you loose all method that you created in the child class
This just don’t work at all …
it throw an error as getByemail is not a method of my model
public function actionTest()
{
$user = new User();
$toto = User::model()->getByEmail('test@test.com');
}
So is it possible to use my methods properly ?
public function actionTest()
{
$user = new User();
$user->getByEmail('test@test.com');
echo $user->id;
$user->notify();
etc...
}
Do you have any ideas ?
I want to have FAT models and skinny controllers.
Maybe it’s a design issue and i must don’t extend those active records .
Any help about this would be very great.