Common uses in the CodeIgniter framework

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.