Home Backend Development PHP Tutorial Common usages in the CodeIgniter framework

Common usages in the CodeIgniter framework

Jun 14, 2018 pm 03:51 PM
codeigniterframework Common usage Summarize

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Summarize the usage of system() function in Linux system Summarize the usage of system() function in Linux system Feb 23, 2024 pm 06:45 PM

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

How to use PHP and CodeIgniter framework for application development How to use PHP and CodeIgniter framework for application development May 10, 2023 pm 08:52 PM

With the popularity and development of the Internet, more and more people are beginning to develop their own websites and applications. PHP is a popular server-side programming language, and the CodeIgniter framework is an open source PHP framework that can help developers quickly build applications and improve development efficiency and code readability. This article will introduce how to use PHP and CodeIgniter framework for application development. Install PHP and CodeIgniter framework Before we start developing the application, we need to first

Git workflow management experience summary Git workflow management experience summary Nov 03, 2023 pm 06:45 PM

Summary of Git workflow management experience Introduction: In software development, version management is a very important link. As one of the most popular version management tools currently, Git's powerful branch management capabilities make team collaboration more efficient and flexible. This article will summarize and share the experience of Git workflow management. 1. Introduction to Git workflow Git supports a variety of workflows, and you can choose the appropriate workflow according to the actual situation of the team. Common Git workflows include centralized workflow, feature branch workflow, GitF

How to write a ppt summary report and how to write it well How to write a ppt summary report and how to write it well Mar 19, 2024 pm 08:16 PM

Summary reports are an essential skill for survival in the workplace. If you have a well-organized PPT summary report, it can not only save the leader's time, but also provide a focused summary of the work, which will definitely impress the leader. How to write a ppt summary report? Let’s take a look! We open a case file and explain based on this case. This case looks a bit outdated, as shown in the picture below. 2. Since we want to modify the PPT just now, let’s explain its existing problems in a targeted manner, as shown in the figure. 3. Here we introduce to students a [color matching] website, the vanschneider.com website. The website here is still very rich in color matching, as shown in the figure. 4. Here we prepare the PPT text material, and then

Explore the origins of nature! The seventh bullet of Google's 2022 year-end summary: How can 'Biochemical Environmental Materials” reap the dividends of machine learning? Explore the origins of nature! The seventh bullet of Google's 2022 year-end summary: How can 'Biochemical Environmental Materials” reap the dividends of machine learning? Apr 11, 2023 pm 07:19 PM

With huge advances in machine learning and quantum computing, we now have new and more powerful tools to collaborate with researchers across industries in new ways and radically accelerate the progress of groundbreaking scientific discoveries. The theme of this year's Google year-end summary is "Natural Science." The author of the article is John Platt, an outstanding scientist at Google Research. He graduated from the California Institute of Technology with a Ph.D. in 1989. Since joining Google Research eight years ago, I have been fortunate to be part of a community of talented researchers applying cutting-edge computing technologies to advance the possibilities of applied science. The team is currently exploring topics in the physical and natural sciences, from helping organizations The world's protein and genome information to benefit people's lives, to the extent of utilization

Summary of ThinkPHP development experience: Tips to improve development efficiency Summary of ThinkPHP development experience: Tips to improve development efficiency Nov 22, 2023 pm 12:28 PM

ThinkPHP is a popular PHP development framework that is flexible, efficient, and easy to use. It is widely used in the development of web applications. In long-term development practice, I have summarized some techniques to improve development efficiency, which I will share with you below. 1. Make full use of the core functions of ThinkPHP. ThinkPHP provides many powerful core functions, such as models, views, controllers, etc. We need to make full use of these functions to simplify the development process. First of all, we must use the MVC design pattern correctly and integrate the business

Summary of the Margin property in CSS Summary of the Margin property in CSS Feb 18, 2024 pm 10:11 PM

Summary of the margin attribute in CSS The margin attribute in CSS is used to set the margins of an element, which can control the spacing between the element and surrounding elements. This article will summarize the margin attribute and provide some specific code examples for reference. The margin attribute has four values, which represent the top, right, bottom and left margins of the element. You can set the margin value in the following ways: Single value: Set the margins in all directions to be equal. For example: .margin{margin:

Analysis and summary of application cases of Baidu AI interface in Java development Analysis and summary of application cases of Baidu AI interface in Java development Aug 13, 2023 pm 12:10 PM

Analysis and summary of application cases of Baidu AI interface in Java development. With the continuous development and application of artificial intelligence technology, Baidu AI interface, as one of them, is widely used in all walks of life. This article will analyze and summarize the application cases of Baidu AI interface in Java development, and illustrate its specific application methods and effects through code examples. 1. Overview of Baidu AI interface Baidu AI interface is a set of services provided to developers through API calls based on Baidu's artificial intelligence technology. It contains rich functions

See all articles