牛骨文教育服务平台(让学习变的简单)
博文笔记

Thinkphp5-前置操作

创建时间:2017-07-27 投稿人: 浏览次数:1880
<?php
namespace appindexcontroller;

use thinkController;

class Index extends Controller
{
    protected $beforeActionList = [
        "first",                                //在执行所有方法前都会执行first方法
        "second" =>  ["except"=>"hello"],       //除hello方法外的方法执行前都要先执行second方法
        "three"  =>  ["only"=>"hello,data"],    //在hello/data方法执行前先执行three方法
    ];

    protected function first()
    {
        echo "first<br/>";
    }

    protected function second()
    {
        echo "second<br/>";
    }

    protected function three()
    {
        echo "three<br/>";
    }

    public function hello()
    {
        return "hello";
    }

    public function data()
    {
        return "data";
    }
}

如注释所言,为TP5的前置操作。
在以下URL中访问:

http://127.0.0.1/demo/public/index.php/index/index/hello

有如下显示:
first
three
hello

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。