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

[Wiki] 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.

Need to make a file like - myfunction.php and put it inside components folder.

In your main.php (config folder)

Add this line in the top of your config main.php file -

require_once( dirname(__FILE__) . '/../components/myfunction.php');

In your components (folder)

Inside the myfunction.php you can write your functions. Like -

function get_my_info() {
 
     //your code here
     //your code here
 
     return value;
 }

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 -

$info = get_my_info();
 
//Or
 
echo get_my_info();

Try this and reduce the time :)..


Viewing all articles
Browse latest Browse all 3361

Trending Articles