This article mainly introduces the common usage of the CodeIgniter framework, and summarizes and analyzes common operating techniques such as CodeIgniter framework controllers, forms, and databases in the form of simple examples. Friends in need can refer to the following
The examples in this article describe Common uses of the CodeIgniter framework. Share it with everyone for your reference, the details are as follows:
1. codeigniter controller super object and attributes
$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');
Configuring the exchange table prefix
$db['default']['dbprefix'] = 'blog_'; $db['default']['swap_pre'] = 'my_';
Then we use the table prefix my_ when writing sql statements, and ci will automatically replace my_ Bit blog_, so dbprefix can be modified at will, which is convenient for us to modify the database name.
For example:
$sql = "SELECT * FROM my_archive";
3. Form submission path
$this->load->helper('url');
Use
site_url('控制器/方法名')
4. Form verification(please refer to the previous article "CodeIgniter Form Verification Method Example Detailed Explanation" "And "Detailed Explanation of CI Framework Form Validation Examples")
5. SQL statement related
① Insert
$this->db->insert('archive',$archive); 返回bool值 $insert_id = $this->db->insert_id(); $this->db->insert_batch('archive',$data); //插入多条
② Query
$query = $this->db->query($sql); //返回Object $query->num_rows() 或者 $query->num_rows 返回查询出多少条 if($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(); //影响行数
④ Delete
$bool = $this->db->delete('tablename', array('id' => '500')); $bool = $this->db->where(array('id' => 500))->delete('tablename'); $this->db->affected_rows(); //影响行
The above is the entire content of this article, I hope it will be helpful to everyone’s study, more related content Please pay attention to PHP Chinese website!
Related recommendations:
How to use CodeIgniter to integrate Smarty
The above is the detailed content of Common usages in the CodeIgniter framework. For more information, please follow other related articles on the PHP Chinese website!