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

You are viewing revision #3 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#4) »

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

1 3
5 followers
Viewed: 37 425 times
Version: Unknown (update)
Category: Tutorials
Written by: Rohit Suthar
Last updated by: Rohit Suthar
Created on: Jul 7, 2014
Last updated: 10 years ago
Update Article

Revisions

View all history

Related Articles