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

[eluser]slowgary[/eluser]
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

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

|-public_html
| |-css/
| |-gfx/
| |-etc/
| |-index.php
|
|-application
|-codeigniter1.7.1

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:
Code:
$system_folder = "../codeigniter1.7.1";
Code:
$application_folder = "../application";

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

El Forum

[eluser]InsiteFX[/eluser]
Hi,

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

and using a controller and view:

Code:
// 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

<head>
    <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";?>" />
</head>

// footer_view.php

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

</div>
&lt;!-- End #footer --&gt;

Enjoy
InsiteFX