search
Homephp教程php手册ThinkPHP框架之实用项

ThinkPHP框架之实用项

Jun 13, 2016 am 10:58 AM
phpsessionthinkphpthreeuseexisttechnologyframeprogram

三、实用项

 

1、 session

 

在php程序中,如果想使用session技术必须要先开启session

 

Session_start();

 

在tp中,session机制默认就是开启的

 

如果我们程序中没有用到session技术,建议在配置文件中关掉session

 

l  config.php

 

       SESSION_AUTO_START

 

默认是开启的

 

l  session('name','value'); 

创建session并赋值

Name:名

Value:值

l  $value = session('name');

对session进行取值

Name:名

l  session('name',null);

清除指定的session

l  session(null);

清除所有session

l  session('?name');

判断指定的session是否存在

 

 

2、 cookie

 

l  cookie('name','value');

创建cookie

l  cookie('name','value',3600);

创建cookie并设置生存时间

l  $value = cookie('name');

对cookie进行取值

l  cookie('name',null);

清除指定的cookie

l  cookie(null);

清除所有cookie

 

 

 

 

 

 

 

 

 

 

 

 

 

3、 验证码

 

如果需要生成中文验证码,需要调用image类下的GBVerify方法进行生成,调用这个方法需要将字体库中的相应的字体文件,放到与image类同级目录下

 

在控制器创建一个操作专门用于生成验证码:

 

在表单中,使用图像的src属性调用以上操作

 

验证时,由于默认的验证码的session经过md5加密,所以比较,我们需要将用户提交的验证码也进行加密,再进行比较

 

 

4、 数据分页

 

setConfig方法的参数:

 

l  header

l  Prev

l  next

l  first

l  last

l  $page->setConfig('header','个会员');

 

 

5、 多表连接

 

l  table

 

select t1.*,t2.*from t1,t2 where t1.id=t2.sid

 

l  join

 

select t1.*,t2.*from t1 left join t2 on t1.id=t2.sid

 

 

 

 

1) table语法:

 

l  table

 

l  $model->  table(‘table1 t1,table t2’)

                 ->where(‘t1.id=t2.sid’)

                 ->select();

 

 

2)join语法:

 

l  $model->  join(‘left(right) join t2 on t1.sid=t2.id’)

                 ->select();

 

 

 

6、 Ajax应用

 

l  Action类提供了ajaxReturn方法用于AJAX调用后返回数据给客户端

 

l  通过配置DEFAULT_AJAX_RETURN进行设置,默认配置采用JSON格式返回数据

 

Statement
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools