Usage Instructions
AG_Asset is really simple to use.
Configurable items
AG_Asset comes with a few configurable items, these are all the names of your assets folders.
$config['assets_route'] = 'assets'; $config['css_route'] = 'css'; $config['images_route'] = 'images'; $config['scripts_route'] = 'scripts';
The first item is the name of your assets folder. The second is the name you have given your css folder. The third is the name of your mages folder and finally the last item is the name of your scripts folder.
Loading the Library
To load AG_Asset place the following line of code into your Controller.
$this->load->library('ag_asset');
Load a CSS File
AG_Asset let's you easily load in CSS files and will automatically build the path to the file and wrap it all up in a <link> tag.
$this->ag_asset->load_css($filename, $subfolder, $media);
This function accepts three parameters. The first is required and is the name of the CSS file you wish to load (including the file extension). The second parameter is optional and is the subfolder you may be storing the file inside the main css folder. You can have as many folders as you like but must still pass this as a string. Finally the last parameter is also optional, and is the media type. It defaults to screen but you can set it to anything as long as it is valid HTML.
Load an Image
AG_Asset let's you easily load in CSS files and will automatically build the path to the file and wrap it all up in an <img> tag and also allows you to specify CSS styles.
$this->ag_asset->load_image($filename, $subfolder, $style);
This function accepts three parameters. The first is required and is the name of the image you wish to load (including the file extension). The second parameter is optional and is the subfolder you may be storing the file inside the main images folder. Once again you can have as many folders as you like but must still pass this as a string. Finally the last parameter is also optional, and is any CSS you wish to add to the <img> tag. The array must be formatted as below.
$style = array( 'type' = 'id', 'value' = 'my_id_name' );
The type is the type of the CSS you are adding, and should either be ID or class. The value is the name of the ID tag or class name you are giving to the image. You can apply multiple class names by separating them by a space, exactly as you would in vanilla HTML.
Load a JavaScript File
AG_Asset let's you easily load in javascript files and will automatically build the path to the file and wrap it all up in a <script> tag.
$this->ag_asset->load_script($filename, $subfolder);
This function accepts three parameters. The first is required and is the name of the javscript file you wish to load (including the file extension). The second parameter is optional and is the subfolder you may be storing the file inside the main css folder.
Return the path only
AG_Asset let's you choose to return the path of the file you are trying to load.
$this->ag_asset->return_path($path);
This function accepts one parameter and by default it is set to FALSE. Simply pass TRUE, or FALSE to set or unset to value to return the path only. This function may be useful in a number of different cases.