2

I am new in Codeigniter. I tried to load my css file but i failed. I search it google apply all solution but its not working.

I also made changes in mu autoload file

$autoload['helper'] = array('url', 'form');

Here is my Controller code with name Login.php

<?php
    class Login extends CI_Controller{
        function index(){
            $this->load->helper('url'); 
            $this->load->helper('html');
            $data['main_content'] = 'login_form';
            $this->load->view('include/template', $data);
        }
    }
?>

And Here is My View Code Name with login_form.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel = "stylesheet" type = "text/css" href = "<?php echo base_url();?>css/style.css">
<title>Untitled Document</title>
</head>

<body>
    <div id="login_form">
        <h1>Login Page..!!</h1>
        <?php
        echo form_open('login/validate_credentials');
        echo form_input('username', 'Username');
        echo form_password('password', 'Password');
        echo form_submit ('submit', 'Login');
        ?>

    </div>
</body>
</html>

Here is my Folder Structure

Config
controller
css
helper
models
views
12
  • 1
    Check your browser console for any errors.. and tell us the errors. Commented Jun 15, 2017 at 5:05
  • @ShaktiPhartiyal how i can do that? Commented Jun 15, 2017 at 5:05
  • 1
    right click on the page and click inspect Commented Jun 15, 2017 at 5:05
  • 1
    @ShaktiPhartiyal Thanks Buddy i found my error. actually i place my css folder in application folder and its need to place outside the application folder :) :) Thanks allot Man Commented Jun 15, 2017 at 5:14
  • 1
    @sunny i have added the answer.. Commented Jun 15, 2017 at 5:19

5 Answers 5

2

Open your browser console by right clicking on your web page and select inspect.

Go to your network requests / console and check what URL you get for your linked files (CSS).

If you find out that the path you have given in your application if different then you need to change your code accordingly to get the appropriate path.

Sign up to request clarification or add additional context in comments.

Comments

0

Assuming your base_url() is the root of your domain (e.g. http://localhost), then it will return the root directory of the application (the directory where CodeIgniter's index.php is stored). So all you have to do is move your css folder up to that directory. I believe it's one step up from the current location of your css folder.

Please also take note that you have to set the base_url() in your CodeIgniter config.php file, like so:

$config['base_url'] = 'http://localhost';

Comments

0

Try this:

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

CI's default webroot is out of application folder which you mentioned.

Comments

0

solved your issue move your css folder out of application folder and place on root structure will be

->application
->css

Comments

0

First maintains your folder structure download cod igniter and start with new structure

Set base url in config file if you can use CI-version 3

Set with your project folder name

$config['base_url'] = 'http://localhost/project_folder_name';

And load css using base_url() :generally we are use bae_url() for load js,css,images

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

Comments

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.