• thinkphp6 非法请求:index/hello


    搭建好tp6后

    Thinkphp6   Index控制器下面建立的hello()方法,不能访问,总是提示非法请求,换成其它方法名都没问题,就是hello不能用.


    http://xxx/index.php/index/hello

    提示

    #0 [0]HttpException in Url.php line 89

    非法请求:index/hello


    原因是

    原因,route/app.php 定义了路由, 定义路由规则后,原来的URL地址将会失效,变成非法请求。


    use think\facade\Route;

    Route::get('think', function () {
         return 'hello,ThinkPHP6!';
    });

    Route::get('hello/:name', 'index/hello');



    定义路由后就只能访问下面的URL地址


    http://xxx/think

    输出:hello,ThinkPHP6!


    http://xxx/hello/thinkphp

    输出:hello,thinkphp



    namespace app\controller;

    use app\BaseController;

    class Index extends BaseController
    {
         public function index()
         {
             return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{
      background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; fon
    t-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</
    span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthi
    nk.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
         }

        public function hello($name = 'ThinkPHP6')
         {
             return 'hello,' . $name;
         }

        public function abc()
         {
             return 'abc';
         }


    public function inject($name)
    {
             return 'Hello,' . $name . '!This is '. $this->request->action();
    }

    可以这样调用

    http://xxx/index/abc

    输出

    abc


    http://xxx/index/inject/name/xxx

    输出:

    Hello,xxx!This is inject

  • 相关阅读:
    Online Object Tracking: A Benchmark 翻译
    线性判别分析(Linear Discriminant Analysis)转载
    网址大全
    计算机视觉学习方法
    计算机视觉顶级期刊会议
    爬取淘宝小姐姐头像
    CSP201512-03画图 90分
    二叉树的基本操作之二叉排序树
    sort排序实现
    冒泡排序实现
  • 原文地址:https://www.cnblogs.com/cute/p/16870222.html
Copyright © 2020-2023  润新知