2

I am totally new in CodeIgnitor. In the controllers folder I created a file named caller.php and I created a file home.php in views. In views I also created a folder named css and I created style.css in that css folder. In views I have some pictures. Those pictures are also part of design. Now I want to use style.css and the pictures. But I can't.

In caller.php I have:

class caller extends CI_Controller
{
    function index()
    {

        $this->load->view('home');  
        // What do I have to write here to load css?
    }
}

In home.php I have:

<html>
<head>

***------what i have to write here to load css--------***

</head>

<body>

<div id="outer">
...
</div>

</body>

</html>

If additional configs are needed please mention that.

1
  • 1
    Your main problem is the structure of your files. The css/ directory shouldn't be inside views/, it should be in a publicly accessible folder. Commented Nov 17, 2012 at 12:49

3 Answers 3

3

Leading on from what Oliver said of including the stylesheet with:

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">

If you have removed index.php from your URL's make sure you include your css directory in the rewrite rule.

RewriteEngine on
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

This is assuming your stylesheet is located in a folder called css at the root of your application.

- index.php
+ system
+ application
+ css
   - style.css

Make sure that you have enabled the URL helper to use commands such as base_url(). This can be done globally inside config/autoload.php by adding url to the helper array.

$autoload['helper'] = array('url');
Sign up to request clarification or add additional context in comments.

6 Comments

what does it mean " removed index.php from your URL's ". can you explain.
yes my css file is located in the root directory in the folder called css
I don't know what actually rewrite rule is?
Have a read though the URL documentation codeigniter.com/user_guide/general/urls.html - It explains about it in there... If you've not done this then it should just work as oliver has explained.
when i write .... <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css"> ... in home.php a blank page appears. when i don't link the style.css then the page shown. Now what can i do?
|
0

add

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">

into home.php between <head> and </head> tags

and make sure the style.css is in a css folder in the main directory

4 Comments

what do you mean by main directory
in the same directory as the application folder, system folder, make a new one called css and place your stylesheet in there
when i load it a blank page appears.
when i write .... <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css"> ... in home.php a blank page appears. when i don't link the style.css then the page shown. Now what can i do?
0

Thanks so much @ Malachi. <link href="<?php echo base_url();?>assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/> is my file path & not working.

I have used

RewriteEngine on RewriteCond $1 !^(index\.php|images|assets|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]

on my .htaccess file & it's working now smoothly. assets is my file file path

1 Comment

You should keep your assets or css/js file on root directory of CI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.