I have the following in the header.php
file which is included in all of my views:
$dh = opendir(Vs.get_class($this).'/js') ;
while($script = readdir($dh)) {
if(!is_dir($script))
{
echo '<script type="text/javascript" src="js/'.$script.'"></script>' ;
}
}
$dh = opendir(Vs.get_class($this).'/css') ;
while($css = readdir($dh)) {
if(!is_dir($css))
{
echo '<link type="text/css" href="css/'.$css.'" rel="stylesheet"/>' ;
}
}
It's purpose is to autoload all the CSS and JS files for a particular view (which has the same name as the controller, hence get_class
).
Should all this be a part of the associated controller or is how I have done it fine?
@sudobangbang Thanks I have edited it now so it is:
foreach(glob(Vs.get_class($this).'/css/*.css') as $cssFile) {
echo '<link type="text/css" href="'.WROOT.$cssFile.'" rel="stylesheet"/>'."\n" ;
}
I do have a base controller class which all my controllers extend from, do you have an example of a helper function you mentioned?
My views file structure is like this:
/views
/views/header.php
/views/footer.php
/views/mypage
/views/mypage/index/php
/views/mypage/css
/views/mypage/js