验证码路由:
$route->get('captcha/[:config]', "\\think\\captcha\\[email protected]");
我们设置的路由:Route::rule('download', "\\app\\home\\controller\\[email protected]");
Route::rule('question', "\\app\\home\\controller\\[email protected]");
Route::rule('q/:docid', "\\app\\home\\controller\\[email protected]");
这样的话访问会报错模板找不到,框架到了:根目录/view去寻找模板了,因此我们要指定模板绝对路径class Index extends BaseController
{
protected $viewPath;
protected function initialize()
{
parent::initialize();
$this->viewPath = root_path() . 'app/home/view/index/';
}
/**
* 下载页面
* @return think\Response
*/
public function download()
{
//...
return View::fetch($this->viewPath . 'download.html');
}
//...
}
如果使用了模板继承,也需要指定模板文件{extend name="../app/home/view/public/base.html"/}
至此,我们访问www.domain.com/question.html就可以访问到home/index/question了有个问题就是url('home/index/question')无法自动生成/question的url地址
最佳答案
