1.页面跳转和重定向
<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\exception\PDOException;
/**
* Class Student
*/
class Student extends Controller
{
public function index()
{
return $this->fetch();
}
public function add()
{
$data = input('post.');
try {
$ret = Db::name('student')->insert($data);
$this->success('添加成功',url('index'));
} catch (PDOException $ex) {
$this->error('添加失败,' . $ex->getMessage());
}
}
}
在上面的代码中出现了 $this->success() 和 $this->error() 方法。
$this->success() 表示跳转成功,如果执行成功,页面会显示“添加成功”,并且将路由指定到当前控制器的index方法。
在页面跳转时,会有3秒默认的等待时间,也可以指定时间:
$this-