ci框架(二),ci框架
ci框架(二),ci框架
自定义SQL语句
当提供的API满足不了我们对SQL语句的要求的时候,我们通常是自己来写SQL语句,CI也提供了比较强大了,能够满足我们需求的一般的sql的API。
1 2 3 4 5 6 7 8 |
|
自定义扩展控制器
在application/core中新建MY_Controller.php
1 2 3 4 5 6 7 8 9 |
|
同时需要在application/config/config.php中配置一下:
1 |
|
自定义扩展模型
在application/models中创建user_model.php
1 2 3 4 5 6 7 8 |
|
在控制器中调用自定义模型
application/controllers:
1 2 3 4 5 |
|
1 |
|
1 2 3 |
|
加载模型的时候可以给模型取一个名字:
1 2 |
|
Url相关函数
在表单验证的时候,需要把数据传给控制器,怎么准确的而且可扩展的写action呢,调用API:
1 2 3 4 5 |
|
在user/add.php视图当中:
1 2 3 |
|
如果是index.php目录的话,用:
1 |
|
这个API。
同时,每次加载url很麻烦,也可是设置成自动加载,在config/config.php中修改:
1 |
|
可能在后面的版本中就没有这个自动加载了。
路由
$route['rouxx/showxx/([\d]+)\.html'] = 'rou/show/$1';//插入这句话
分页
- 必须知道的一些参数
总共有多少条记录
一页要有多少条记录
总共多少页
当前页前后要显示多少个分页链接
- 设置一些CI分页类基本参数
1 2 3 4 5 6 7 8 |
|
- 调用CI的分页类
1 |
|
- 执行分页方法
1 |
|
- 输出分页链接
1 |
|
- 查询部分数据(limit)
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
上传文件
视图 /views/up.php:
1 2 3 4 5 6 |
|
控制器:
- 定义一个数组,设置一些与上传相关的参数
1 2 3 4 5 6 7 |
|
还可以设置其他的一些额外参数,详细看用户手册。
- 调用CI的上传通用类,并执行上传
1 2 3 4 |
|
- 接收出错信息或成功信息
1 2 3 4 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Session
利用CI类实现session登录
- 修改配置文件(config.php)
1 2 |
|
- 加载SESSION类
1 |
|
- 创建SESSION
1 2 |
|
- 查看SESSION
1 |
|
- 删除SESSION
1 |
|
$config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = TRUE $config['sess_use_database'] = FALSE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300;
- 一次性数据,只能读取一次
1 2 3 4 |
|
php CI 框架怎从数据库中取值(一个二维数组)以表格的形式显示到view层
控制层
function test_func(){
//获取model页面需要的两个参数
$competition_id = $_GET["competition_id"];
$report_class = $_GET["report_class"];
$this->load->model("Action"); //引入model
$data["head"] = $this->Action->get_report_item($competition_id, $report_class); //引用model的函数
$this->load->view("test_result",$data); //将结果显示在test_result.php页面中
}
view层:
添加结果显示
//此处选择了循环输出从控制层传输的结果
字段名称(含义) //该td中显示的是你从数据库、即model层中获取到的数据的含义,想显示多少,显示哪个,在这里确认 |
test; ?> echo “123”; }?> php CI框架问题?小弟是初学者
在view文件里可以直接用$title了 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In PHP programming, the array_sum function is a very practical function that can calculate the sum of all elements in an array. However, when we need to calculate the sum of a column of elements in a two-dimensional array, we may encounter some trouble. This article will introduce how to use the array_sum function in PHP to calculate the sum of elements in a column of a two-dimensional array. First, we need to understand the concept of two-dimensional arrays. A two-dimensional array is an array containing multiple arrays, which can be regarded as a table. Each array represents a table

How to convert a php array from two dimensions to a one-dimensional array: 1. Use loop traversal to traverse the two-dimensional array and add each element to the one-dimensional array; 2. Use the "array_merge" function to merge multiple arrays into An array. Pass the two-dimensional array as a parameter to the "array_merge" function to convert it into a one-dimensional array; 3. Using the "array_reduce" function, you can process all the values in the array through a callback function and finally return a result.

In PHP programming, we often need to operate on arrays, including obtaining the value of a specified column. PHP provides a very convenient function - array_column, which can help us quickly obtain the value of a specified column in a two-dimensional array. This article will introduce how to use the array_column function. Basic usage of array_column function: array_column(array$array,mixed$column_key[

How to reverse a two-dimensional array in php: 1. Create a php sample file; 2. Define a two-dimensional array; 3. Reverse the array through the "array_reverse($a,true);" function; 4. Use "print_r" to print Just reverse the two-dimensional array.

How to convert a two-dimensional array to a one-dimensional array in PHP In PHP development, you often encounter scenarios where you need to convert a two-dimensional array into a one-dimensional array. This article will introduce several common methods to help you complete this task easily. Method 1: Use loop traversal The simplest and most straightforward method is to use a loop to traverse a two-dimensional array and add each element to a new one-dimensional array. Here is a code example using this method: functionflattenArray($array){$result

PHP has a two-dimensional array, which is a special type of array that can store other arrays as elements. The declaration and access of a two-dimensional array are very simple. You can use the "array" function to create a two-dimensional array and use indexing or association. Arrays, as their elements, are very useful in practical programming and can be used to process various complex data structures.

Detailed explanation of PHP5.5 functions: How to use the array_column function to extract a certain column in a two-dimensional array. In the PHP5.5 version, the array_column function was introduced. It is a very practical function that can extract a specified column of data from a two-dimensional array. This comes in handy when working with large amounts of data, allowing us to quickly get the data we need. The basic syntax of the array_column function is as follows: arrayarray_column(array$

Question Write a C program that uses runtime compilation to calculate the sum and product of all elements in a two-dimensional array. Solution runtime compilation or initialization is also known as dynamic allocation. Allocating memory at execution time (runtime) is called dynamic memory allocation. The functions calloc() and malloc() support dynamic memory allocation. The functions calloc() and malloc() support dynamic memory allocation. p>In this program, we will calculate the sum of all elements of a 2D array and the product of all elements at runtime. Logic is used to calculate the sum of all elements in a 2D array - printf("Sumarrayis:");for(i=0;i<2;i++){&
