【发布时间】:2020-07-16 03:54:41
【问题描述】:
我在一个有多个组织的项目上使用 php codeigniter。每个组织都有自己的网站,我需要根据组织名称将每个用户重定向到其组织网站。
我让这个部分运行。以 localhost 为例:
localhost/application/ -> 转到正确的视图;
localhost/home/nameoftheorganization -> 转到正确的组织视图;
但是有没有办法消除“Home”控制器?
我的 routes.php 看起来像这样:
$route['default_controller'] = 'home';
$route['404_override'] = 'home/page_not_found';
$route['translate_uri_dashes'] = FALSE;
我的 Home.php 控制器如下所示:
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->load->database();
$this->load->library('session');
// $this->load->library('stripe');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
if (!$this->session->userdata('cart_items')) {
$this->session->set_userdata('cart_items', array());
}
}
public function index() {
$this->home();
}
public function home($domain = '') {
if($domain != ''){
$frontend = $this->crud_model->get_frontend_information($domain);
}else{
$frontend = $this->crud_model->get_frontend_information('myapp');
}
foreach($frontend AS $arr){
if(is_array($arr)){
$website[$arr['key']] = $arr['value'];
}
}
$this->session->set_userdata('website', $website);
$page_data['page_name'] = "home";
$page_data['page_title'] = get_phrase('home');
$this->load->view('frontend/'.get_frontend_settings('theme').'/index', $page_data);
}
htaccess 看起来像这样
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
【问题讨论】:
标签: php .htaccess codeigniter