CodeIgniter framework common usage work summary, codeigniter framework

Source: Internet
Author: User

CodeIgniter framework common usage work summary, codeigniter framework

This example describes common usage of the CodeIgniter framework. We will share this with you for your reference. The details are as follows:

1. codeigniter controller super objects 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');

Configure the prefix of the exchange table

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

Therefore, we use the table prefix my _ when writing SQL statements, and ci will automatically change my _ to blog _. Therefore, dbprefix can be changed as needed, so that we can modify the database name.

For example:

$sql = "SELECT * FROM my_archive";

3. Form submission path

$this->load->helper('url');

Use

Site_url ('controller/method name ')

4. Form Verification(Refer to the previous article "CodeIgniter Form Verification Method Instance details" and "CI framework form verification example details")

5. SQL statement Problems

① Insert

$ This-> db-> insert ('archive', $ archive); returns the bool value $ insert_id = $ this-> db-> insert_id (); $ this-> db-> insert_batch ('archive', $ data); // insert multiple

② Query

$ Query = $ this-> db-> query ($ SQL); // return Object $ query-> num_rows () or $ query-> num_rows returns the number of results to be queried 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> ', '000000')-> update ('archive', $ data ); $ this-> db-> affected_rows (); // The number of affected rows.

④ Delete

$ Bool = $ this-> db-> delete ('tablename', array ('id' => '123 ')); $ bool = $ this-> db-> where (array ('id' => 500)-> delete ('tablename '); $ this-> db-> affected_rows (); // affects the row

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.