当前位置:首页 > Web开发 > 正文

] ]; 路由的使用 自定义路由 application/index/controller/Video.php ? p

2024-03-31 Web开发

【thinkphp5框架的目录布局,,以及使用框架model 、controler、view的使用,以及错误调试和日志记录

ThinkPHP5 在php5.5版本以上”No input file specified“问题解决:

  public/.htaccess文件中的

  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

  在默认情况下会导致No input file specified.

  改削成

  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

  问题解决

配置文件的使用

application/index.controller/Demo.php

<?php namespace app\index\controller; use think\Config; class Demo extends Base{ // 配置文件的使用 public function config() { // 默认一页显示15条 $config = Config::get("paginate"); dump($config);//15 $config = config("paginate.type"); dump(config("?paginate"));//boolean true $config = config("paginate.type"); dump(config("?paginate111"));//boolean false dump(Config::has("paginate"));//boolean true dump(config("cyy")); // array (size=1) // cyy‘ => int 1 dump(config("redis.host"));//string ‘127.0.0.1‘ } }

application/extra/redis.php

<?php // 配置文件的使用 return [ "host" => "127.0.0.1", ];

application/index/config/php

<?php // 配置文件的使用 return [ "cyy" => [ ‘cyy‘ => 1, ] ];

路由的使用

自界说路由

application/index/controller/Video.php

<?php namespace app\index\controller; class Video extends Controller { // 自界说路由 public function getVideo() { $id = input("param.id"); // ?id=2 // => 域名/video/2 dump($id); } }

application/route.php

<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2016 All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( ) // +---------------------------------------------------------------------- // | Author: liu21st <[email protected]> // +---------------------------------------------------------------------- use think\Route; // 自界说路由 域名/video/2 // Route::rule("video/:id", "index/Video/getVideo"); //Route::get("video/:id", "index/Video/getVideo");// 界说Get请求路由 //Route::post("video/:id", "index/Video/getVideo");// 界说Post请求路由 // 组合写法 Route::get([ ‘video/:id‘ => ["index/Video/getVideo", [], [‘id‘ => ‘\d+‘]], ]);

控制器的使用

application/index/controller/Demo.php

<?php namespace app\index\controller; use think\Config; use think\Request; class Demo extends Base{ /** * 初始化 * @auth cyy * @return [type] [description] */ public function _initialize() { dump("这是initialize"); } public function test() { // 数组转json格局返回 return json(["as" => 1, "cyy" => "test"]); } public function hello() { var_dump(input("param.")); return "index-index-hello"; } // 控制器-跳转 public function abc() { $id = input("param.id", 0, "intval"); if($id == 1) { $this->success("操纵告成", "admin/index/index"); }elseif($id == 2) { $this->error("操纵掉败"); } } // 控制器-重定向 public function ef() { $this->redirect("hello", ["id" => 1, "ms" => 123]); //redirect("https://baidu.com"); } // 控制器-请求 public function requestData() { $request = Request::instance(); //访谒?ids=2 dump(request()->isPost());//boolean false dump(input("?get.ids"));//boolean true dump(request()->has("ids", "get"));//boolean true } }

application/index/controller/Base.php

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31467.html