1.安装后的单应用更改为多应用
1)、执行composer require topthink/think-multi-app命令
2)、删除app下的controller文件夹
2.windows 下开启调试
1)、.env文件创建不了,在linux服务器上创建该文件,压缩、下载、解压到app同级目录,设置APP_DEBUG = true
3.Apache 下去掉url中的index.php
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
有的服务器需要“?”,有的服务器去掉“?”,不会的可以尝试两次
4.return view();出错(tp6不在内置模板引擎)
如果使用tp的模板引擎,用如下命令:composer require topthink/think-view
5.控制器initialize中redirect函数不起效
管理后台正常是页面访问先判断是否有登录的session,没有跳转登录页面
tp5.1我是这样写的
<?php
namespace app\back\controller;
use think\Controller;
class Common extends Controller
{
public function initialize()
{
if(!session('uid')){
$this->redirect('back/login/index');
}
}
}
换成tp6错误代码如下(根本不跳转):
<?php
namespace app\back\controller;
use think\App;
use app\BaseController;
use think\facade\Session;
class Common extends BaseController
{
public function initialize()
{
if(!session('uid')){
return redirect('/back/login/index');
}
}
}
通过手册和网上查询找到了两种方法:
1)、<?php
namespace app\back\controller;
use think\App;
use app\BaseController;
use think\facade\Session;
class Common extends BaseController
{
public function initialize()
{
if(!session('uid')){
return redirect('/back/login/index')->send();
}
}
}
注意此方法跳转后地址栏地址不会改变
2)、
<?php
namespace app\back\controller;
use app\BaseController;
use think\exception\HttpResponseException;
use think\facade\Session;
class Common extends BaseController
{
public function initialize()
{
if(!session('uid')){
return $this->redirectTo('/back/login/index');
}
}
public function redirectTo(...$args)
{
throw new HttpResponseException(redirect(...$args));
}
}
6.验证码的使用
首先要安装验证码:composer require topthink/think-captcha
模板显示验证码及点击刷新:<div style="width:50%;float:left"><img id="vcode" src="{:captcha_src()}" οnclick="this.src='{:captcha_src()}?'+Math.random()" style="width:100%;height:50px"></div>
验证失败的原因是:tp6验证码需要开启session打开如下行就可以了