CodeIgniter Forums
[MagicResources] Autoload specific.js & .css files - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: [MagicResources] Autoload specific.js & .css files (/thread-707.html)



[MagicResources] Autoload specific.js & .css files - 50l3r - 01-07-2015

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


RE: [MagicResources] Autoload specific.js & .css files - Rufnex - 01-07-2015

Nice done, thx for sharing!


RE: [MagicResources] Autoload specific.js & .css files - 50l3r - 01-07-2015

it's time to share with the community Wink