• 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

  • 相关阅读:
    websocket简单理解
    对两个列表合成一个列表后进行排序
    爬取今日头条财经版块新闻
    Python的hasattr(),getattr(),setattr()
    Django基础
    pymysql模块的使用
    我一定要学好英语
    Django项目的创建
    MySQL数据库(安装+增删改查)
    jQuery
  • 原文地址:https://www.cnblogs.com/cute/p/16870222.html
Copyright © 2020-2023  润新知