略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Yaf_Plugin_Abstract::routerShutdown

2024-05-02

Yaf_Plugin_Abstract::routerShutdown

(Yaf >=1.0.0)

Yaf_Plugin_Abstract::routerShutdownThe routerShutdown purpose

说明

public Yaf_Plugin_Abstract::routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response): void

这个钩子在路由结束之后触发,通常被用于登陆检查。

参数

request

response

返回值

范例

示例 #1 Yaf_Plugin_Abstract::routerShutdown()example

<?php
class UserInitPlugin extends Yaf_Plugin_Abstract {

    public function 
routerShutdown(Yaf_Request_Abstract $requestYaf_Response_Abstract $response) {
        
$controller $request->getControllerName();

        
/**
         * Use access controller is unecessary for APIs
         */
        
if (in_array(strtolower($controller), array(
            
'api',
        ))) {
            return 
TRUE;
        }

        if (
Yaf_Session::getInstance()->has("login")) {
            return 
TRUE;
        }

        
/* Use access check failed, need to login */
        
$response->setRedirect("http://yourdomain.com/login/");
        return 
FALSE;
    }
?>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/yaf-plugin-abstract.routershutdown.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3