Reputation: 35
My routes.php as Below:
$controller_list = array('showmenu','aboutus'); // etc you will have to put all your controllers in this array
foreach($controller_list as $controller_name)
{
$route[$controller_name] = $controller_name;
$route[$controller_name.'/(:any)'] = $controller_name.'/$1';
}
$route['([a-zA-z_]+)'] = 'main/index/$1';
//$route['default_controller'] = "home";
$route['404_override'] = '';
I want to call all controller in main class like localhost/foldername/main/about(different slugs) how to do that?
Upvotes: 0
Views: 186
Reputation: 69
in your routes.php
$default_controller = "main";
$route['default_controller'] = $default_controller;
$route['aboutus'] = 'aboutus';
$route['slug'] = 'showmenu';
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';
Upvotes: 0
Reputation: 69
Try this first you have to set your default controller
$default_controller = "main";
$route['default_controller'] = $default_controller;
then you have to define your methods
$route['same url'] = 'aboutus';
$route['same url'] = 'showmenu';
Upvotes: 0
Reputation: 35
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Main extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->database();
$this->load->model("menu_model");
$this->load->model("main_model");
}
public function index() {
$data['category']= $this->menu_model->getCategory('$lang');
$data['subcategory']= $this->menu_model->getSubCategory('$lang');
$this->load->view('vwHeader',$data);//Left Menu
}
public function showmenu()
{
$menutitle = $this->uri->segment(3);
$query = $this->db->get_where('category',array('namecategory'=>$menutitle));
$data['content'] = $this->main_model->show_content($menutitle);
$data['category']= $this->menu_model->getCategory('$lang');
$data['subcategory']= $this->menu_model->getSubCategory('$lang');
$this->load->view('vwMain',$data);//Left Menu
}
public function menu()
{
$data['category']= $this->menu_model->getCategory('$lang');
$data['subcategory']= $this->menu_model->getSubCategory('$lang');
$this->load->view('vwHeader',$data);//Left Menu
}
public function aboutus() {
$arr['page'] ='about';
$data['category']= $this->menu_model->getCategory('$lang');
$data['subcategory']= $this->menu_model->getSubCategory('$lang');
$this->load->view('vwHeader',$data);//Left Menu
$this->load->view('vwAboutus',$arr);
}
public function contactus() {
$arr['page'] ='contactus';
$data['category']= $this->menu_model->getCategory('$lang');
$data['subcategory']= $this->menu_model->getSubCategory('$lang');
$this->load->view('vwHeader',$data);//Left Menu
$this->load->view('vwContactus',$arr);
}
}
This is controller main.php
Upvotes: 0
Reputation: 69
i exactly don't understand what you want to say but you can define each function separately in your routes.php for simple and fine url like this:
$route['whatever you want in your url'] = 'your controller name/your function name';
this will like:
localhost/foldername/(different slugs)
Upvotes: 1