我使用codeigniter,我正在使用我的维护控制器,但想知道请求它进入我的维护路线的最佳方法是什么。并且不确定是否让控制器正确无误。
我的路线 //目录最终用户
$route['maintenance'] = "catalog/common/maintenance";// Need to request this route.
$route['account/login'] = "catalog/account/login";
$route['account/register'] = "catalog/account/register";
维护控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Maintenance extends CI_Controller {
public function index() {
if ($this->config->set_item('config_maintenance')) {
$route = '';
if (isset($this->request->get['route'])) {
$part = explode('/', $this->request->get['route']);
if (isset($part[0])) {
$route .= $part[0];
}
}
// Show site if logged in as admin
$this->load->model('model_setting');
}
}
}
只是因为我想在我的目录/前端有控制器,但能够在登录时在我的管理员中打开和关闭
答案 0 :(得分:0)
如果您创建自定义控制器, 您可以在__constructor中检查网站是否处于维护状态。 那些继承自它的东西将适用规则。
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
// Check to see if the user is anything other than
// admin, and redirect them.
// Do your own authoring here.
if(config_item('maintenance_mode') && $currentuser->group != "admin"){
return $this->load->view('maintenance');
}
}
}