Adding CSS into CodeIgniter View

To add a css we have to follow these steps:

• define general css that used. Open “config.php” within directory CodeIgniter\system\application\config.

• Add following code. The line posisi is up to you. I add at last line before ?>

$config[‘css’] = ‘style.css’;

• Create a file named mystyles.css within root application: \CodeIgniter\.

• Enter example code like this:

/* CSS Document */

body

{

margin:0 auto;

background: #333333 url(../images/header.gif) repeat-x;

font: normal 16px ‘SolaimanLipi’, ‘Verdana’, ‘Times New Roman’;

}

input{ font: normal 100% ‘SolaimanLipi’, ‘Verdana’, ‘Times New Roman’;

font-size:16px;

float:left;

}

select {font: normal 100% ‘SolaimanLipi’, ‘Verdana’, ‘Times New Roman’;}

#header

{

margin:0 auto;

width:100%; height:59px;

}

#banner

{

margin:auto;

height:150px;

}

#logo{

margin-top:2.5em;

height:4em;

width:20em;

background:url(../images/votebd_admin_logo.png) no-repeat;

}

/*page*/

Open controller file named “districtList.php” within CodeIgniter\system\application\controllers. Add bold lines from following code:

load->library(‘session’);

$this->load->helper(‘url’);

$table = “district_list”;

$this->load->model(‘Votebd_model’,”, TRUE);

$data[‘base’] = $this->config->item(‘base_url’);

$data[‘css’] = $this->config->item(‘css’);

$data[‘query’] = $this->Votebd_model->getSelectAllSQL($table);

$this->load->view(‘admin/districtlist_view’, $data);

}

}

?>

Then, update “districtlist_view.php” within CodeIgniter\system\application\views\admin. Update , like this:


<head><link rel=”stylesheet” type=”text/css” href=”<?php echo “$base/$css”?>”></head>

And within add class=”adminlist” into table tag:

<TABLE class=”adminlist” WIDTH=”97%” BGCOLOR=”#e9ecef” BORDER=”1″ CELLSPACING=”0″ CELLPADDING=”1″ align=”center”>

<TR align=”center”>

<TH width=”4%”>নং</TH>

<TH width=”3%” align=”center”> </TH>

<TH width=”33%”>জেলার নাম</TH>

<TH width=”60%”>জেলা বর্ণনা</TH>

</TR>

</TABLE>

Point your browser to http://localhost/CodeIgniter/index.php/admin/districtlist. My view now look like this:

districtlistview

Advertisements

7 Responses

  1. It seems you have given the solution for only a single CSS file.. what abt multiple CSS … or JS or FLASH files and image files…

    I think this will come more handy…
    http://codeigniter.com/wiki/Asset_Helper/

  2. abjoint unalterability curculionist inobvious hydroperitoneum snottily head semimonthly
    Tenkiller Marine Service Boat Parts
    http://www.infonyte.com/

  3. Thank you for sharing.

    I’d recommend to use valid XHTML code.

    I made a home based solution for multiple .css files using an array. In a header file check if $data[‘css’] is a single string or an array. If it is an array, I iterate through each item to render the tag …

  4. Interesting article and one which should be more widely known about in my view. Your level of detail is good and the clarity of writing is excellent. I have bookmarked it for you so that others will be able to see what you have to say.

    gaming chair review

  5. I am glad to be a visitor of this staring web site, regards for this rare information!

  6. I find that many times articles written this way do not keep the attention of the reader, this was not the case in this article. Excellent read, thanks for the post and looking forward to more!

  7. best yet Here’s some pass forward: Thought for the day? : I won’t rise to the occasion, but I’ll slide over to it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: