Welcome Guest, Not a member yet? Register   Sign In
Best location to store css & img
#1

[eluser]RpR[/eluser]
A noob question but where would be the appropriate place to store the css and images?
In a subfolder of the views or ...

Thanks in advance.
#2

[eluser]awpti[/eluser]
/
--/css
--/images
--/system
----/application/


Basically, right off your docroot is the most simplistic method.

<img src="/images/...." />
#3

[eluser]Maxximus[/eluser]
I use one directory to store my images, css, js:

/assets/js
/assets/css
/assets/img

for the following reason: It's easier (and safer) used in combination with the following .htaccess:
Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^(/index\.php|/assets|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

All other incoming requests will be routed to index.php. You can easily extend the exception list by adding a |/directory to it.
#4

[eluser]ebot[/eluser]
your css and image should be stored at the base root, thats where you have you index.php file.
if you have got any probe to load let me know i will give the codes i used in building my blog and how to include both css and images, and for the images create a sub folder where you have the index.php its better that way
#5

[eluser]drewbee[/eluser]
Personally I put them all in an interface directory off of the root:

/public_html/interface/images/
/public_html/interface/css/
/public_html/interface/js/
#6

[eluser]RpR[/eluser]
[quote author="ebot" date="1218118375"]your css and image should be stored at the base root, thats where you have you index.php file.
if you have got any probe to load let me know i will give the codes i used in building my blog and how to include both css and images, and for the images create a sub folder where you have the index.php its better that way[/quote]
Ok I've followed this approach. But then I am facing a problem to set the correct src voor images and css files.

I've read about the url helper but do I really need to use it for every image and css file?
#7

[eluser]RpR[/eluser]
Anyone?
#8

[eluser]Frychiko[/eluser]
Assuming you have /public/img for your image folder:

Use the following inside a <IMG> tag.
Code:
$image = base_url()."public/img/image.png";

Example:
Code:
<img src='&lt;?=base_url()."public/img/image.png"?&gt;'>

Use the following to test whether a file exists
Code:
$file = "./public/img/image.png";

For CSS images it's relative to your CSS folder, so if you have
Code:
public/
img/
css/
This would be how to do it:

Code:
a.go_back {
    background:url(../img/arrow_undo.png) no-repeat 2px center;
    padding:0.3em;
    padding-left:20px;
    text-decoration:none;    
}
#9

[eluser]ebot[/eluser]
you css and images files should be where you have the index.php file; that is at the root.
yeah on you config.php file add this code:
for your css add this
Code:
$config['css'] = "default.css";
; default.css is the name of my css file, so you can have any name for that. on you controller add this codes
Code:
$this->base = $this->config->item('base_url');
    $this->css = $this->config->item('css');
at function like this one:
Code:
function Blog()
  {
    parent::Controller();
    $this->base = $this->config->item('base_url');
    $this->css = $this->config->item('css');
    $this->load->model('Blog_model');
    
    
  }

or let give you one of my controllers so as you to know what to do:
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends Controller{

    var $base;
    var $css;

  function Blog()
  {
    parent::Controller();
    $this->base = $this->config->item('base_url');
    $this->css = $this->config->item('css');
    $this->load->model('Blog_model');
    
    
  }
  
  function index()
  {
    $data['css'] = $this->css;
    $data['base'] = $this->base;
    $data['title']="Welcome to My Blog | ebottabi.com";
    $data['entries']=$this->Blog_model->get_last_ten_entries(20);
    $data['comments']=$this->Blog_model->commentnum();
    $this->load->view('view', $data);
  }
  
  function gotopost($post_id)
  {
    $this->load->library('validation');
    $data['css'] = $this->css;
    $data['base'] = $this->base;
    $data['title']="Blog Post";
    $data['heading']="Post";
    $data['posts']= $this->Blog_model->getpost($post_id);
    
     $data['getcomments'] = $this->Blog_model->getcomments($post_id);
    $this->load->view('post',  $data);

    
  }
  function add()
  {
    $this->load->library('validation');
    
    $data['css'] = $this->css;
    $data['base'] = $this->base;
    $data['title']="Add Post | ebottabi.com";
    $this->load->view('addpost', $data);
  }
  
  function logout()
    {
        $this->load->model('Admin_model');
        $this->load->library('session');
        $this->load->helper('url');
        
        $user_id = $this->session->userdata('user_id');
        $session_id = $this->session->userdata('session_id');
        $user_id = $this->Admin_model->checkID($user_id, $session_id);
        
        if($user_id != 0)
        {
            $this->Admin_model->logout($user_id);
            $this->session->sess_destroy();
        }
        redirect('/admin', 'refresh');
    }
    
    function insert()
    {
        $this->load->library('validation');
        $data['css'] = $this->css;
        $data['base'] = $this->base;
        $data['title']="Add Post | ebottabi.com";
        $data['heading']="Add Post";
        $rules['title']    = "required";
        $rules['postdate']    = "required";
        $rules['summary']    = "required";
        $rules['post']    = "required";
                
        $this->validation->set_rules($rules);
        
        if ($this->validation->run() == FALSE)
        {  
            $data['message']="Add Post Incomplete!";
            $this->load->view('addpost', $data);
        }
        else{
            $data['message']="Add Post was Successfully ";
            $this->db->insert('posts', $_POST);
            $this->load->view('addpost',$data);
        }
        
    }
    
    function nav()
    {  
        
        $data['css'] = $this->css;
        $data['base'] = $this->base;      
         $data['title']="My Blog CMS Navigation Page";
        $data['heading']="Blog CMS";
        $data['entries']=$this->Blog_model->get_last_ten_entries(20);
        $this->load->view('nav_view', $data);
    }
    
    function comments()
    {
        
        $data['css'] = $this->css;
        $this->load->library('validation');
        $data['base'] = $this->base;      
         $data['title']="Post your comments";
        $this->load->view('comments', $data);
    }
    
    function comment_insert($post_id)
    {
        $this->load->library('validation');
        $data['css'] = $this->css;
        $data['base'] = $this->base;
        $data['title']="Post Your Comments | ebottabi.com";
        $data['heading']="Post Your Comments";
        $rules['name']    = "trim|required|min_length[6]|max_length[12]|xss_clean";
        $rules['email']    = "trim|required|valid_email|xss_clean";
        $rules['comments']    = "trim|required|min_length[6]|max_length[80]";
        $this->validation->set_rules($rules);
        if ($this->validation->run() == FALSE)
        {  
            $data['message']="Your comments Incomplete!";
            $goto=$this->gotopost($_POST['post_id']);
        }
        else{
            
            $comment = $this->Blog_model->insertcomm($_POST);
            $data['message']="Your comments has been Posted!";
            $this->load->view('comments', $data);
            
        
    }    
    
                
}

    
    }
    



?&gt;

these are the codes i used in developing my blog and personal site. at the view section use these for the header:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $title?&gt;&lt;/title&gt;
&lt;link href="&lt;?php echo base_url();?&gt;default.css" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;
. i think this is all you need for the css and for the image use this, note that your image folder should be at the root, where you have your index.php, so this is the code for the images:
Code:
<img src='&lt;?=base_url()."image(folder where the images are found)/name of the image.png"?&gt;'>




Theme © iAndrew 2016 - Forum software by © MyBB