user1250526
user1250526

Reputation: 309

Stylesheet not working with Code Igniter

I am trying to fit a stylesheet into view with CodeIgniter, please bare in mind I am new to CI.

So the stylesheet seems to be included right and I am checking the location, but it still doesn't seem to change a thing..

this is my view:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>newsletter</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>application/css/style.css" media="screen" />
</head>

<body>
<label for="name"> HI TESTING STYLING & EMAILING</label>
<div id="newsletter_form">
<?php echo form_open('email/send'); ?>

<?php

$name_data = array(
    'name' => 'name',
    'id' => 'name',
    'value' => set_value('name')
);



?>

<p><label for="name">Name: </label> <?php echo form_input($name_data); ?></p>

<p><label for="email">Email Address: </label><input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>">

    <p><?php echo form_submit('submit', 'Submit'); ?></p>
    <?php echo base_url(); ?>application/css/style.css
    <?php echo validation_errors('<p class="error">'); ?>

<?php echo form_close(); ?>
</div>
</body>
</html>

as you can see I am echoing out the url just to make sure and it is correct although it is forbidden.. not sure if this is standard CI procedure or if this is the cause.. I am working on my localhost.

and this is my stylesheet...

label{
display: block;
background: #FFF;
}

.error{

 color: #373737;
}

#newsletter_form{
background: #000;
width: 100px;
}
input[type=submit]{
border: 1px solid #c62828;
background: #aa2929;
color: #e3e3e3;
padding: .5em;
cursor: pointer;    

}
 input[type=submit]:hover{
background: #9c2222;

}

thanks!! I am confused, any help is appreciated :)

Upvotes: 0

Views: 1576

Answers (3)

Wayne Tun
Wayne Tun

Reputation: 589

You can use base_url(); method in CI.

Example

CI APP Folder
-application
-system 
-css (supposed you have style.css inside in that folder named 'css')

You use in your views like this

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

This might also work

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

To set base_url() method path, you can check in application/config/config.php

Upvotes: 0

Branden S. Smith
Branden S. Smith

Reputation: 1161

It is not good practice to put css/js files in your applications folder. Put it in a separate folder called "css" in your root and call it with base_url('css/style.css'); Your root folder should look like this

-Root
  -application
    (all of your CI files)
  -css
    -Style.css
  -js
    -script.js
    -plugins.js

It is good if CodeIgniter is blocking Application/Css because that means it's protecting your raw files in your application folder properly :)

Upvotes: 1

esilvas
esilvas

Reputation: 310

As Branden mentioned above CI will block access to that css file via the .htaccess file in that folder. I would put it another folder as he mentioned. I would also consider moving your index.php file to another folder (putting it outside of the web root) and then edit index.php to reflect the change. Something like this:

Root
- application
- public
   index.php
- system

Keep your web assets where you like, but I tend to keep them in the public folder.

Upvotes: 0

Related Questions