CodeIgniter Forums

Full Version: Best practice for handling assets (images/css etc)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear CI community!

Our assets folder is at the same level as the application and system folder.

So, we have created a rule in .htaccess to handle URIs starting with /assets

Is there a best practice to handling assets within the CI framework?

If we want to continue to keep assets outside CI, but don't want to do .htaccess based routing, is there a way to set up routes in CI for this scenario.

Thanks in advance
You can create your helper to point to your assets folder, my is always in the route of my server but this is how you can do it using a asset() method


PHP Code:
('BASEPATH') OR exit('No direct script access allowed');

 * asset ()
 * ------------------------------------------------------------------------
 * Assumes that all resources are in a asset directory in the root
 * along with index.php.
 * asset('path/filename.ext')
if ( ! function_exists('asset'))
     * method ()
     * ---------------------------------------------------------------------------
     * @param   $uri
     * @return  mixed
function asset($uri)
$_ci =& get_instance();


You will have to play around with this but you should be able to make it work.
Just put them inside your webroot, or at symlink there ... anything else is extra work for nothing.