This article mainly introduced the CodeIgniter framework common usage, combined with the simple example form summarizes the CodeIgniter frame controller, the form, the database and so on common operation skill, the need friend can refer to the next
Examples of this article describe common uses of the CodeIgniter framework. Share to everyone for your reference, as follows:
1. CodeIgniter controller Super Objects and properties
$this->load; $this->load->database (); $this->load->view (); $this->load->helper ();
$this->uri; $this->uri->segment (3);
$this->input;
2. Database Configuration
$this->load->database (); $this->db->query (' SELECT * from Blog_user ');
Configure Exchange Table prefixes
$db [' Default '] [' dbprefix '] = ' blog_ '; $db [' Default '] [' swap_pre '] = ' my_ ';
Then we write the SQL statement with My_ This table prefix, CI will automatically put My_ transposition Blog_, so, Dbprefix can be arbitrarily modified, convenient for us to modify the database name.
Such as:
$sql = "SELECT * from My_archive";
3. Form submission Path
$this->load->helper (' url ');
Use
Site_url (' controller/Method name ')
4, form verification (can refer to the previous article "CodeIgniter form verification method Examples of details" and "CI framework form Verification Example detailed")
5. SQL statement Related
① Insertion
$this->db->insert (' archive ', $archive); Returns the bool value $insert_id = $this->db->insert_id (); $this->db->insert_batch (' archive ', $data); Insert more than one
② Query
$query = $this->db->query ($sql); Returns Object$query->num_rows () or $query->num_rows returns the number of If queries ($query->num_rows () > 0) {return $query Result ();//$query->row () $query->result_array () $query->row_array ()}else{return false;} $query->last_query ();
③ Update
$bool = $this->db->where (' ID > ', ' 74835 ')->update (' archive ', $data); $this->db->affected_rows (); affect the number of rows
④ Delete
$bool = $this->db->delete (' tablename ', array (' id ' = ') '), $bool = $this->db->where (array (' id ' = )->delete (' tablename '); $this->db->affected_rows (); Affect row
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!