Hi,
I’m new to OOP and here is my question.
I’ve a function defined in controller/AbcController.php and want to use it under the models/Abc.php. How to do it?
Thanks!
Hi,
I’m new to OOP and here is my question.
I’ve a function defined in controller/AbcController.php and want to use it under the models/Abc.php. How to do it?
Thanks!
Why do you need it? Can you provide an example?
I have a form and some fields need to do calculation before "submit". And the formula contains some values that is belongs to other table or record. So, instead of using the long command "Yii::app()->db->createCommand(xxx)->queryRow() );" to retrieve the relevant value every time. I want to write a function inside the controller so I could call it when I need it within the "protected function beforeSave()" under the "models".
i.e. xsql("select field1,field2 from table1")
public function xsql($sql) {
echo implode(",",Yii::app()->db->createCommand($sql)->queryRow() );
}
Is this approach correct? Or, there is some other proper way to do it?
Thanks!
I normally use: modelnameclass::model()->thefunctioncall
don’t you think is easier?
Found the solution here:
http://www.yiiframework.com/wiki/31/use-shortcut-functions-to-reduce-typing/
Thanks!