CodeIgniter 101

Installation

1. Download

2. Extract to /var/www

3. rename folder to ci213

3. go to http://localhost/ci213

4. see welcome page

Hello World Controller

Try edit welcome.php to phong.php

1. class name should be the same as filename
2. The index() will be at http://localhost/ci210/index.php/phong
3. If we add more function i.e. testfunction() will be at http://localhost/ci210/index.php/phong/testfunction

/application/controller/phong.php

<!--?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');<br ?-->
class Phong extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$this->load->view('welcome_message');
                // $this->load->view('welcome_message', array("foo" => "bar","bar" => "foo"));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Model Example
1. configure database ( username, password, database ) at
/application/config/database.php

/application/model/phong_model.php

class Phong_model extends CI_Model {
          function get_data(){
                return mysql_query("select * from tablename")
                // or we can use ActiveRecord. i.e. $this->db->get('tablename');
          }
public function testfunction(){
           $this->load->database();
           $this->load->model('Phong_model');
           echo $this->phong_model->get_data();
}

Tips : user guide is at http://localhost/ci213/user_guide