Request and response Thinkphp

A. Request object acquisition method

1. request () helper function to get

2. think \ Request class acquired

3. When utilizing the simple interest frame injection methods Request Request object in the frame app think class is instantiated

<?php
namespace app\index\controller;

use think\Request;

class Index
{
    /**
     * @param Request $request
     * @return string|void
     */
    public function index(Request $request)
    {
        #$request = request();
        #$request = Request::instance();
        return dump($request);
    }
}

II. Use the Request object

<?php
namespace app\index\controller;

use http\Params;
use think\Request;

class Index
{
    /**
     * @param Request $request
     * @return string|void
     * @url http://localhost/news/5.html?name=jiang
     */
    public function index(Request $request)
    {
        /* 获取域名 */
        dump($domain = $request->domain());   # 返回域名 $domain = http://localhost
        dump($pathinfo= $request->pathinfo ()); # return the domain name and? The pathinfo = value between News $ / 5.html 
        the dump ( $ path = $ Request -> path ());          # $ News path = /. 5 

        / * request type * / 
        the dump ( $ Method = $ Request -> Method ( ));      # return request method $ method = the GET; 
        the dump ( $ request -> isGet ());               # Analyzing the type requested method returns true determination of type is not returned to false 
        the dump ( $ request -> isajax ());              #
 
        / * request parameter * / 
        the dump ( $ ID = $ request-> GET ( "ID"));     # GET received value does not include pathinfo portion returns null where 
        the dump ( $ ID = $ Request -> param ( 'ID'));    # $ ID =. 5 
        the dump ( $ name = $ Request -> param ( 'name')); # $ name = Jiang 
        # the session ( "name", 'jiangfeilong'); # set the session 
        the dump ( $ the session = $ Request -> the session ()); # Get sssion objects not setting the session returns an empty array of 
        the dump ( $ session_name = $ Request -> session ( "name"));# Returns the value of the session name 
        dump ( $ the cookie =$ Request -> cookie ());    # acquires cookie object returns the cookie array of 
        the dump ( $ PHPSESSID = $ Request -> cookie ( 'the PHPSESSID')); # returns sessionId a cookie value 
        / * Get the url parameter using the helper functions * / 
        the dump ( $ ID = INPUT ( 'ID' )); 


        / * Get operation controller module * / 
        the dump ( $ Module1 = $ Request -> Module1 ());   # obtaining module where the current index 
        the dump ( $ controller = $ Request -> controller ()); # returns the current controller is here Index class 
        the dump ( $ Action =$ Request -> Action ()); # Returns the current operation returned here is the index () method Index class index module 

        / * Get URL * / 
        the dump ( $ URL = $ Request -> URL ());   # Returns / after url here /news/5.html?name=jiang 
        the dump ( $ the baseUrl = $ Request -> the baseUrl ()); # portion between the return url / Nos here /news/5.html? 
       

    } 
}

 

Guess you like

Origin www.cnblogs.com/jiangfeilong/p/11204571.html