I am using php codeigniter on a project that has several organizations. Each organization will have its own website, I need to redirect each user to its organization website according to the organization name.
I got this partially running. Using localhost as example:
localhost/application/ -> Goes to the correct view;
localhost/home/nameoftheorganization -> Goes to the correct organization view;
But is there a way to eliminate the "Home" controller?
My routes.php looks like this:
$route['default_controller'] = 'home';
$route['404_override'] = 'home/page_not_found';
$route['translate_uri_dashes'] = FALSE;
My Home.php controller looks like this:
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 looks like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]