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

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 :)...

0 3
5 followers
Viewed: 21 865 times
Version: 1.1
Category: Tutorials
Written by: Rohit Suthar
Last updated by: Rohit Suthar
Created on: Jul 7, 2014
Last updated: 3 years ago
Update Article

Revisions

View all history

Related Articles