How to start codeIgniter framework Reviewed by Momizat on . First download codeIgniter library from http://ellislab.com/codeigniter Setting of starting time Change database connection in appliction/config/database.php fi First download codeIgniter library from http://ellislab.com/codeigniter Setting of starting time Change database connection in appliction/config/database.php fi Rating: 0

How to start codeIgniter framework

First download codeIgniter library from http://ellislab.com/codeigniter

codeIgniter structure

Setting of starting time

  • Change database connection in appliction/config/database.php file
    <?php 
    $db['default']['hostname'] = XXXXXXXXXX;
    $db['default']['username'] = XXXXXXXXX;
    $db['default']['password'] = XXXXXXXX;
    $db['default']['database'] = XXXXXXXXXX;
    $db['default']['dbdriver'] = 'mysql';
    ?>
  • set autoload libraries,helper in appliction/config/autoload.php file
    <?php 
    $autoload['libraries'] = array('database','session');
    $autoload['helper'] = array('url', 'file');
    ?>
  • set value in appliction/config/config.php file
    <?php 
    $config['base_url']	= 'http://www.site.com/';
    $config['index_page'] = '/';
    $config['encryption_key'] = '59c95189ac895fcc1c6e1c38d067e244';
    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
    ?>
  • set value in .htaccess file
    
    <IfModule mod_rewrite.c>
        RewriteEngine On	
    	RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
    	RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
    
        RewriteBase /	
        
        RewriteCond %{REQUEST_URI} ^system.*
    
        RewriteRule ^(.*)$ /index.php?/$1 [L]
        
        RewriteCond %{REQUEST_URI} ^application.*
    
        RewriteRule ^(.*)$ /index.php?/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-f
    
        RewriteCond %{REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php?/$1 [L]
    
    </IfModule>
    <IfModule !mod_rewrite.c>
        ErrorDocument 404 /page-not-found
        ErrorDocument 403 /page-not-found
    </IfModule>  
    
    <ifModule mod_headers.c>
        Header set Access-Control-Allow-Origin: *
    </ifModule>
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>
    
  • Change default controller and rewrite url in appliction/config/routes.php file
    <?php 
    $route['default_controller'] = "main/home";
    $route['page-not-found'] = "main/error404";
    $route['content-(:any)/(:any)'] = "main/content/$1/$2";
    $route['artical-(:any)'] = "main/artical/$1/";
    ?>
  • create a controller main in appliction/controllers/main.php file
    <?php 
     if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Main extends CI_Controller {	
    
    	public function index()
    	{				
    		
    		$this->load->view('dashboard');	
    	}
    }
    ?>
  • create a model user_model in appliction/models/user_model.php file
    <?php 
    class User_model extends CI_Model
    {
        function __construct()
        {
            // Call the Model constructor
            parent::__construct();
        }
    	
        
    	function getallusers(){    
        	$this->db->select('*');
    		$this->db->from('users');		
        	$query = $this->db->get();   	
        	$result=$query->result_array();
        	return $result;    
        }
    }
    ?>
  • create a dashboard view in appliction/views/dashboard.php file
     
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Dashboard</title>
    </head>
    
    <body>
    <table width="100%" border="0">
      <tr>
        <td width="16%">Name</td>
        <td width="12%">Email</td>
        <td width="31%">Phone</td>
        <td width="41%">Address</td>
      </tr>
      <tr>
      <?php foreach($result as $resultvl){?>
        <td><?php echo $resultvl['name'];?></td>
        <td><?php echo $resultvl['email'];?></td>
        <td><?php echo $resultvl['phone'];?></td>
        <td><?php echo $resultvl['address'];?></td>
      </tr>
      <?php }?>
    </table>
    </body>
    </html>
    
    

Leave a Comment

© 2014 Powered By