Common usages in the CodeIgniter framework

不言
Release: 2023-04-01 08:30:01
Original
1174 people have browsed it

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();
Copy after login

$this->uri;
$this->uri->segment(3);
Copy after login

$this->input;
Copy after login

2. Database configuration

$this->load->database();
$this->db->query('SELECT * FROM blog_user');
Copy after login

Configuring the exchange table prefix

$db['default']['dbprefix'] = 'blog_';
$db['default']['swap_pre'] = 'my_';
Copy after login

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";
Copy after login

3. Form submission path

$this->load->helper('url');
Copy after login

Use

site_url('控制器/方法名')
Copy after login

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); //插入多条
Copy after login

② 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();
Copy after login

③ Update

$bool = $this->db->where('id >','74835')->update('archive', $data);
$this->db->affected_rows(); //影响行数
Copy after login

④ Delete

$bool = $this->db->delete('tablename', array('id' => '500'));
$bool = $this->db->where(array('id' => 500))->delete('tablename');
$this->db->affected_rows(); //影响行
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template