Welcome Guest, Not a member yet? Register   Sign In
Best practice for handling assets (images/css etc)
#1

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
Krish
Reply
#2

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

./application/helpers/asset_helper.php

PHP Code:
<?php
defined
('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.
 *
 * USAGE:
 *
 * asset('path/filename.ext')
 */
if ( ! function_exists('asset'))
{
    
/**
     * method ()
     * ---------------------------------------------------------------------------
     *
     * @param   $uri
     * @return  mixed
     */
    
function asset($uri)
    {
        
$_ci =& get_instance();

        return 
$_ci->config->base_url('assets/'.$uri);
    }


You will have to play around with this but you should be able to make it work.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Just put them inside your webroot, or at symlink there ... anything else is extra work for nothing.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB