CodeIgniter Forums

Full Version: [MagicResources] Autoload specific.js & .css files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is a library who include all javascript and css necesary files. Avoid include unnecesary resources in every pages and load automatically resources based on a config file.

Oficial Helpers autoloaded: Url

How to use:

  1. Configure the application/config/resources.php config file
    PHP Code:
    //Resources applied to all methods of controller
    $config['resources_class'] = array("WELCOME","CONTROLLER1","CONTROLLER2");

    //List of resources of every controller's methods
    $config['resources'] = array(    "welcome.index"         => array("PARTICLES"),    "controller1.index"     => array("FONTAWESOME"),);

    //Resources loaded of every pages
    $config['resources_default'] = array("BOOTSTRAP","JQUERY""ANALYTICS"); 

  2. Define resources in application/config/Magicresources.php -> set_resource method:
    PHP Code:
    case "RESOURCE"//Name of the resource
    return  array("css" =>  array("paths/to/css/files"),"js" =>   array("paths/to/js/files"));
    break; 

  3. Load library
    PHP Code:
    $this->load->library('magicresources'); 

  4. In the view, call Magic Resources's render method
    PHP Code:
    $this->magicresources->render_resources('css'); 

Link to library: https://github.com/50l3r/CI-MagicResources
Nice done, thx for sharing!
it's time to share with the community Wink