thinkPHP URL access

ThinkPHPSingle entry mode access application, all requests for the application is directed to the inlet of the application file, the system from URLthe parsing module current request parameter, the controller and operator, the following is a standard URLaccess format:

http://domainName/index.php/模块/控制器/操作 

Wherein index.phpit is called the application file entry (entry file may be hidden note will be mentioned later).

prompt:


ThinkPHP module concept in the application directory is actually a subdirectory, and the official specification is the directory name in lowercase, so the module name in all lowercase, regardless of whether the URL open case conversion, module name will be forced to lower case.

Application indexmodule Indexcontroller is defined as follows:

<?php

namespace app\index\controller;

class Index
{ public function index() { return 'index'; } public function hello($name = 'World') { return 'Hello,' . $name . '!'; } } 

If we have direct access to the entrance documents, because the URL is no module, controller and operator, the system will default access module (index) following default controller (Index) default action (index), so the following are equivalent access of:

http://tp5.com/index.php http://tp5.com/index.php/index/index/index 

If you want to access the controller hello method, you need to use the full URL address

http://tp5.com/index.php/index/index/hello/name/thinkphp 

After visiting the URL address of the page output is:

Hello,thinkphp!

Since the nameparameter is optional, and thus may be used

http://tp5.com/index.php/index/index/hello 

After visiting the URL address of the page output is:

Hello,World!

By default, URL address controller and operator names are not case-sensitive, so the following access is actually equivalent to:

http://tp5.com/index.php/index/Index/Index http://tp5.com/index.php/index/INDEX/INDEX 

If your controller is a hump, for example, define a HelloWorld controller ( application/index/controller/HelloWorld.php):

<?php
namespace app\index\controller;

class HelloWorld
{ public function index($name = 'World') { return 'Hello,' . $name . '!'; } } 

Access the correct URL address (the address can be used to generate url method) should be:

http://tp5.com/index.php/index/hello_world/index 

The system will automatically locate the HelloWorldcontroller class to operate.

If you use

http://tp5.com/index.php/index/HelloWorld/index 

It will report an error, and prompts the Helloworldcontroller class does not exist.

If you want to access a strict case-sensitive (so you can support access control method hump) can be set in the application configuration file:

// 关闭URL自动转换(支持驼峰访问控制器)
'url_convert' => false, 

After closing the URL automatically converted, you must use the following URL address access (controller name must be strictly control the use of the name of the class does not include a controller suffix):

http://tp5.com/index.php/index/Index/index http://tp5.com/index.php/index/HelloWorld/index 

prompt:


Access method of operation itself will not be affected URL automatically converted, but will affect the default template rendering output.

If your server environment does not support the pathinfoURL access method, you can use a compatible manner, for example:

http://tp5.com/index.php?s=/index/Index/index 

Where the variable sname that can be configured.

5.0 no longer supports common URL access, so the following access is invalid, you will find that no matter what, are the default controller with access to input and operation ^ _ ^

http://tp5.com/index.php?m=index&c=Index&a=hello

Guess you like

Origin www.cnblogs.com/xu1115/p/10977601.html