phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


CodeIgniter - Form: Adding CSS

Tag: CodeIgniter, framework, MVC, CSS   Category: PHP Framework
post: 24 Feb 2008 read: 2,903


CodeIgniter Form Step By Step Tutorial - Part 7: At previous post, we talk about how to collect all parameters at one general method at model. Now, we see another advantage of that way. For example, we will add a css. Follow these steps:
  1. define general css that used. Open "config.php" within directory CodeIgniter\system\application\config.
  2. Add following code. The line posisi is up to you. I add at last line before ?>
    
    $config['css'] = 'mystyles.css';
    
  3. Create a file named mystyles.css within root application: \CodeIgniter\.
  4. Enter example code like this:
    
    h1{
    	font-family:Verdana, Arial, Helvetica, sans-serif;
    	font-size:30px;
    }
    p{
    	font-family:Georgia, "Times New Roman", Times, serif;
    	font-size:12px;
    }
    #menu{
    	height:50px;
    }
    #menu ul{
    	list-style-type:none;
    	margin-left:0px;
    }
    #menu li{
    	float:left;
    	padding:10px;
    }
    #footer{
    	font-family:Arial, Helvetica, sans-serif;
    	font-size:10px;
    }
    
  5. Open model file named "books_model.php" within CodeIgniter\system\application\models. Add two lines like line 12 and 13 following code:
    
    <?
    class books_model extends Model{
    	
      function books_model(){
    	parent::Model();
    	$this->load->helper('url');				
      }
    	
      function general(){
    	$this->load->library('MyMenu');
    	$menu = new MyMenu;
    	$data['base']		= $this->config->item('base_url');
    	$data['css']		= $this->config->item('css');		
    	$data['menu'] 		= $menu->show_menu();
    	$data['webtitle']	= 'Book Collection';
    	$data['websubtitle']= 'We collect all title of 
    		                   books on the world';
    	$data['webfooter']	= '© copyright by step 
    		                   by step php tutorial';
    		
    	return $data;	
      }
    }
    ?>
    
  6. Then, update "books_main.php" within CodeIgniter\system\application\views. Update <head></head>, like this:
    
    <html>
    <head>
    <link rel="stylesheet" type="text/css" 
          href="<?php echo "$base/$css"?>">
    </head>
    <body>
    <div id="header">
    <? $this->load->view('books_header'); ?>
    </div>
    <div id="menu">
    <? 	$this->load->view('books_menu'); ?>
    </div>
    
    test list
    
    <div id="footer">
    <? $this->load->view('books_footer'); ?>
    </div>
    
    </body>
    </html>
    
  7. Last, update "books_input.php" within CodeIgniter\system\application\views. Update <head></head>, like this:
    
    <html>
    <head>
    <link rel="stylesheet" type="text/css" 
          href="<?php echo "$base/$css"?>">
    </head>
    <body>
    <div id="header">
    <? $this->load->view('books_header'); ?>
    </div>
    <div id="menu">
    <? $this->load->view('books_menu'); ?>
    </div>
    
    test input
    
    <div id="footer">
    <? $this->load->view('books_footer'); ?>
    </div>
    
    </body>
    </html>
    
Point your browser to http://localhost/CodeIgniter/index.php/books/main. May be get like this: codeigniter form - use css


Series this article:
OOP Pattern - Registry: Monostate Registry Pattern
OOP Pattern - Registry: Embedded Registry
CodeIgniter - Form: Adding CSS

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting