CodeIgniter Forums

Full Version: How to config style sheet in CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]PEN Vannak[/eluser]
Dear CodeIgniter Members,

I just start a new project by using CodeIgniter to develop. I want to use style sheet that put in the folder called "css" that stays out side the folder "system". How can I include this file to my views?

Could you tell me how to config it?

Best regard.

El Forum

Just do it. Create a folder outside of your system folder called 'CSS', store your CSS files in it, then include them in your views.

El Forum

Best way is to regroup CI folders as a whole anyway, is my experience.
Assuming your webroot is named public_html:

| |-css/
| |-gfx/
| |-etc/
| |-index.php

This way, the only executable php file in your webroot is index.php. The rest is outside webroot and cannot be accessed directly. Your current CI installation is in its own folder so if you wish to upgrade, you just substitute codeigniter1.7.1 with whatever version you wish.

All that is required for this to work is tweaking two lines of code in index.php:
$system_folder = "../codeigniter1.7.1";
$application_folder = "../application";

Place you CSS in public_html in public_html/css and link to it like you always do.

El Forum


This is how I did it using a value in the application/config folder config.php

and using a controller and view:

// config.php
| Path to html sytle sheets
| Prototype:
$config['css'] = "public_html/css/main.css";

| Copyright Information
| Prototype:
$config['copyright'] = "Copyright© 2008 -";
$config['copyend']   = "by Your Company Name. all rights reserved Worldwide.";

/* End of file config.php */
/* Location: ./system/application/config/config.php */

// Controller.
$data['css']        = $this->config->item('css');

// Copyright Notice.
$data['copyright']    = $this->config->item('copyright');
$data['year']        = date("Y");
$data['copyend']    = $this->config->item('copyend');

$this->load->view('home', $data);

// html view file.
<?php $this->load->view('header_view'); ?>
<?php $this->load->view('footer_view'); ?>

// header_view.php

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo $mywebtitle ?></title>
    <base href= <?php //echo "../application/views/$base";?> />
    <meta <?php echo $myrobots ?> />
    <link rel="stylesheet" type="text/css" href="<?php echo "http://localhost/apc_cms/$css";?>" />

// footer_view.php

<!-- Begin #footer -->
<div id="footer">
&lt;?php echo "$copyright $year $copyend"; ?&gt;<br />

&lt;!-- End #footer --&gt;