Thursday, 31 July 2014

To add Very Custom Global Functions on Joomla 2.5 / 3+

If you are struggling to find a place to put any custom global functions (not exclusive to any components, plugins or modules) on Joomla 2.5, 3.0 & more, the best place I reckon would be under;


Where I have created the custom/ folder and created the global.php file where you can put all the global functions as you like;

But, before that please add the below lines of code at the bottom of the loader.php file which is located /root/libraries/loader.php

// Import the custom library for global loader if necessary.
if ( file_exists(JPATH_PLATFORM.'/custom/global.php'))
    require_once JPATH_PLATFORM.'/custom/global.php';
Once you completed above steps, you can access those functions on global.php from anywhere from within project.

Below is the example of function written on global.php file.

// To print passed parameter string on preformatted text format.
function print_me($str)
    echo '<pre>';
    echo '</pre>';

May be there would be better approach to this issue, but I did as above. Please keep on comment me if you guys have any other way.

No comments:

Post a Comment

Please post any queries and comments here.