Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 2941

[Wiki] [Updated] How to create & call custom global function in whole application?

$
0
0

In this wiki I will show how to create own custom global function. It may be save the space and reduce the time.

In your components -

You need to make a file like - MyClass.php and put it inside components folder. Inside the MyClass.php you can write your functions. Like -

class MyClass extends CApplicationComponent {
 
 public function get_my_info() {
 
     //your code here
     //your code here
 
     return value;
 }
 
}

In your main.php (config folder) -

'components' => array(
        'myClass' => array(
            'class' => 'ext.components.MyClass',
        ),

Now this function is accessible in whole application (controller, view etc.), Directly call the function get_my_info() any where and it will return your value. Like -

$myInfo = Yii::app()->myClass->get_my_info();

thanks to @hippyjim for better help... Try this and reduce the time :)...


Viewing all articles
Browse latest Browse all 2941

Trending Articles