• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing Image On CSS with Codeigniter

#1
My file structure is


Code:
application

assets

assets > catalog

assets > catalog > theme

assets > catalog > theme > default

assets > catalog > theme > default > stylesheets > default.css

assets > catalog > images > holder.png

system

index.php



I need to access the image on my css but I cannot seem to get path.

What would be the correct path using the background url


Code:
body {
    padding-top: 64px;
    /*background: #E7E7E7;*/
    background: url('../assets/catalog/images/holder.png');
}
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
IIRC, the CSS URL is relative to the folder containing the CSS file.
Reply

#3
(07-09-2016, 01:40 AM)ciadmin Wrote: IIRC, the CSS URL is relative to the folder containing the CSS file.

The css file is in couple of sub folders in side assets if thats what your meaning in my structure?
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#4
Hi wolfgang1983,

ciadmin is trying to tell you that you should access the CSS file by pointing out directly the path; so, accessing the CSS file should work this way:

Code:
background: url('./assets/catalog/images/holder.png');


If your project is itself in a subfolder, then you should add that part too:

Code:
background: url('./projects/my_project/assets/catalog/images/holder.png');

However, as a good practice to point to any of your assets (CSS, JavaScripts, images etc.) you can use the base_url() function from CodeIgniter. More about it here. However, based on your current project structure, you can't use it for this situation because the CSS files don't get processed by PHP, so the function won't be actually called.

Hope this helps! Smile
Reply

#5
I see where your CSS is.
I suggest that the background URL would be '../../../images/holder.png', going up 1 folder to default, up 1 more to themes, up 1 more to catalog, and then down into images.
Reply

#6
in order to use holder png's you need to load the holder.js javascript file if it is not loaded.

Here is a method to add to a asset_helper.php

PHP Code:
/* ------------------------------------------------------------------------
 *
 * Assumes that all resources are in a asset directory in the root
 * along with index.php and that the base_url is set in the config.php file.
 *
 * USAGE:
 *
 * asset('path/filename.ext')
 *
 * @access    public
 * @param    string
 * @return    string
 */
if ( ! function_exists('asset'))
{
    function 
asset($uri)
    {
        
$_ci =& get_instance();

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


if you want you can change the return to add in your catalog path there.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
Thanks all got it to work now.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.