CodeIgniter Forums
Accessing Image On CSS with Codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Accessing Image On CSS with Codeigniter (/showthread.php?tid=65666)



Accessing Image On CSS with Codeigniter - wolfgang1983 - 07-08-2016

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');
}



RE: Accessing Image On CSS with Codeigniter - ciadmin - 07-09-2016

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


RE: Accessing Image On CSS with Codeigniter - wolfgang1983 - 07-09-2016

(07-09-2016, 12: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?


RE: Accessing Image On CSS with Codeigniter - gxgpet - 07-09-2016

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


RE: Accessing Image On CSS with Codeigniter - ciadmin - 07-09-2016

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.


RE: Accessing Image On CSS with Codeigniter - InsiteFX - 07-09-2016

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.


RE: Accessing Image On CSS with Codeigniter - wolfgang1983 - 07-09-2016

Thanks all got it to work now.