Home php教程 php手册 thinkphp四种url访问方式详解

thinkphp四种url访问方式详解

Jun 06, 2016 pm 08:16 PM
thinkphp url Way access

这篇文章主要介绍了thinkphp四种url访问方式,简单分析了ThinkPHPmvc相关概念并重点讲述了URL的四种访问方式,具有一定的参考借鉴价值,需要的朋友可以参考下

本文实例分析了thinkphp的四种url访问方式。分享给大家供大家参考。具体分析如下:

一、什么是MVC

  thinkphp的MVC模式非常灵活,即使只有三个中和一个也可以运行。

M -Model 编写model类 对数据进行操作

V -View  编写html文件,,页面呈现

C -Controller 编写类文件(UserAction.class.php)

二、ThinkPHP的MVC特点    (简单了解)

三、ThinkPHP的MVC对应的目录  (简单了解)

M 项目目录/应用目录/Lib/Model

V 项目目录/应用目录/Tpl

C 项目目录/应用目录/Lib/Action

四、url访问C      (简单了解)

五、url的4种访问方式    (这是重点!!)

1.PATHINFO 模式 --重点 在后面使用非常多,如果想传多个参数可以使用键1/值1/键2/值2方法

复制代码 代码如下:

域名/项目名/入口文件/模块名/方法名/键1/值1/键2/值2

2.普通模式也称为重写模式

复制代码 代码如下:

域名/项目名/入口文件?m=模块名&a=方法名&键1=值1&键2=值2

3.REWRITE重写模式,去掉入口文件便于SEO优化

复制代码 代码如下:

域名/项目名/模块名/方法名/键1/值1/键2/值2

4.兼容模式

复制代码 代码如下:

域名/项目名/入口文件?s=模块名/方法名/键1/值1/键2/值2

如何修改PATHINFO地址中的/改成-在Home/Conf/config.php中

复制代码 代码如下:

'URL_PATHINFO_DEPR'=>'-',//修改RUL的分隔符,把地址栏的参数部分/换成:域名/项目名/入口文件/模块名-方法名-键1-值1-键2-值2

在index.php中开启调用模式,为了在后产模式中不让文件缓存影响开发

复制代码 代码如下:

define('APP_DEBUG',ture);//如果设置为ture不缓存文件,false则缓存文件

REWRITE模式开启方法

在httpd.conf中查找rewrite_module modules/mod_rewrite.sl 把#去掉重启服务,在入口文件下新建.htaccess.php,重写文件是去掉index.php的意思:

复制代码 代码如下:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

 

希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

What is the difference between html and url What is the difference between html and url Mar 06, 2024 pm 03:06 PM

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How to solve the problem of inaccessibility after Tomcat deploys war package How to solve the problem of inaccessibility after Tomcat deploys war package Jan 13, 2024 pm 12:07 PM

How to solve the problem that Tomcat cannot successfully access the war package after deploying it requires specific code examples. As a widely used Java Web server, Tomcat allows developers to package their own developed Web applications into war files for deployment. However, sometimes we may encounter the problem of being unable to successfully access the war package after deploying it. This may be caused by incorrect configuration or other reasons. In this article, we'll provide some concrete code examples that address this dilemma. 1. Check Tomcat service

See all articles