Reputation: 32823
I recently began a new project using CodeIgniter. This is a huge project with several CSS, js and image files. So I need to know whether CodeIgniter has the capability to automatically read all the CSS and js files and include them on the page? It will be pretty hard for me to add all those file manually. If it is possible, then how?
Upvotes: 0
Views: 240
Reputation: 1227
Make a helper with a function like this:
function include_javascript()
{
$dir = "JS_DIR";
if($handle = opendir($dir))
{
while(false !== ($entry = readdir($handle)))
{
if($entry != "." && $entry != "..")
{
$extension = explode(".", $entry);
if(end($extension) == "JS" || end($extension) == "js")
{
// Include file
echo '<script type="text/javascript" src="'.site_url($dir."/".$entry).'"></script>';
}
}
}
closedir($handle);
}
}
Then in your view:
<?php include_javascript(); ?>
Upvotes: 2
Reputation: 4305
Yes you can do that in codeIgniter. What you need to do is create new folder outside of your application folder in codeIgniter (CSS folder, JS folder and Images Folder). You just keep all those files in respective folders. After that you just create inc folder in your views in that you just write a new view file in that include all your JS, CSS files. Like a Header file. Include that header file in every view file. There you can get all of your css properties in all of your pages with one include. For images you need to do it manually because you are going to use different images in different places. I hope this will be useful for you.
Upvotes: 1