【发布时间】:2015-10-06 13:32:26
【问题描述】:
在 PHP MVC 结构中重定向到另一个控制器的正确方法是什么?
假设我有我的控制器类:
abstract class controller {
public function __construct() {
// code here
}
abstract protected function index();
protected function redirect($location = 'index') {
header('location:' . URL . $location);
die(); // <-not shure if this die is right here
}
}
在另一个类中,我需要验证一个条件,如果为假则重定向到另一个地方
class loginController extends controller {
public function __construct() {
parent::__construct();
// More code here
}
public function index() {
if ($this->session->verifyUserStatus()) {
$this->redirect('admin');
}
$this->view->render('login');
}
}
我是否需要在重定向器末尾调用 die() 函数?还是正常结束脚本就可以了?
问候
【问题讨论】:
标签: php redirect model-view-controller exit