Hi everyone im new with codeigniter. my routes.php is
$route['default_controller'] = "Maincontroller";
$route['(:any)'] = "Maincontroller/user_index/$1";
i want to search people if they type in the URL = www.site.com/username
but my problem is when going to other controller. should i route all my controllers?
$route['default_controller'] = "Maincontroller";
$route['somecontrollers'] = 'somecontrollers';
$route['(:any)'] = "Maincontroller/user_index/$1";
then how about my methods.
i tried this remap
public function _remap($method, $params = array())
{
if (method_exists(__CLASS__, $method)) {
$this->$method($params);
} else {
$this->user_index($method);
}
}
but this only works properly in controller which is not default, and i get the result i want. but as i apply this in my default controller it doesnt work well.
Hope this one help you!
$route['Maincontroller/(:any)'] = 'Maincontroller/user_index/$1';
$route['somecontrollers/(:any)'] = 'somecontrollers/user_index/$1';
$route['(:any)'] = "user_index/$1";
Related
I have a site that I want to pass directly to the controller method without going through the class in codeigniter.
https://website.com/product_number instead of https://website.com/index/product_number
I want that to go directly to my main controller method.
config/routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
controllers/Welcome.php
function index($product_number)
{
//process $product_number output
}
Would this be possible in codiegniter?
Open config/routes.php then add this line to it
$route['(.+)'] = 'welcome/index/$1'; I hope this helps your situation.
Open
/application/config/config.php
then find this line
$config['base_url'] = 'https://website.com/index/';
and Replace with
$config['base_url'] = 'https://website.com/';
I hope this Aswer very helpful for you.
I am struggle with URI rerouting in my codeigniter version(2.2.0)application.
Here is my routes.php
$route['details/(:num)'] = 'agent/manage_agents/$1';
And in my view file
foreach($data as $value) {?>
Manage
}?>
But i will get 404 error.
In my Controller file
class Agent extends CI_Controller {
public function manage_agents($id)
{
echo $id;
}
}
UPDATE
Finally i found Which causes the problem.In my routes.php
$route['(:any)'] = "spotmyticket/$1"; when hide this line everything works fine.
Here is my complete routes.php
$route['404_override'] = '';
$route['default_controller'] = "spotmyticket";
$route['ticket']="ticket";
$route['ticket/(:any)'] = $route['ticket'].'/$1';
$route['captcha'] = "captcha";
$route['captcha/(:any)'] = "captcha/$1";
$route['admin'] = "admin";
$route['admin/(:any)'] = "admin/$1";
$route['userdashboard'] = "userdashboard";
$route['userdashboard/(:any)'] = "userdashboard/$1";
$route['fbci'] = "fbci";
$route['fbci/(:any)'] = "fbci/$1";
$route['(:any)'] = "spotmyticket/$1";
$route['agent-management'] = 'agent/index';
$route['register'] = "agent/agent_register";
$route['test'] = 'agent/test';
$route['details/(:any)'] = 'agent/manage_agents/$1';
Please define $route['(:any)'] = "spotmyticket/$1"; as the last rule in routes.php. Everything will be fine. This rule is for any url so all rules defined after this rule will be ignored.
If you are writing this route:
$route['details/(:num)'] = 'agent/manage_agents/$1';
so that you may pass any integer value (like you are passing $value['id']), then try using (:any) instead of (:num). So your route should be:
$route['details/(:any)'] = 'agent/manage_agents/$1';
I got error "Unable to determine what should be displayed. A default route has not been specified in the routing file"
I have two controllers 1.signup and 2.login_control !
How to set routes in routes.php file ? my baseurl is http://localhost:1337/PhpProject1/
my code is below in routes.php file
$route['signup/(:any)'] = 'signup';
$route['login_control/(:any)'] = 'login_control';
$route['404_override'] = '';
First, specified your default route by your first controller.
Like this-
$route['default_controller'] = "signup";
and then add your another controller.
$route['login-control'] = 'login_control';
Do like this
Syntax
$route['how_its_look_like'] = 'controller_name/method';
Example
$route['signup'] = 'login/signup';
$route['login'] = 'login/login';
$route['logout'] = 'login/logout';
$route['404_override'] = '';
Links
Ccodeigniter Routing Examples
Working on codeigniter project.
Got stuck with routes.
I want to access en/company/login through en/login, so how do I define routes then?
Right now routes code looks like this:
// URI like '/en/about' -> use controller 'about'
$route['^(en|lv)/(.+)$'] = "$2";
// '/en', '/lv' URIs -> use default controller
$route['^(en|lv)$'] = $route['default_controller'];
$route['company/login'] = "login";
tried:
$route['^(en|lv)/company/login'] = "login";
Obviously, Im not getting something.
Can you help please?
Your problem is (i had the same) that this:
$route['^(en|lv)/(.+)$'] = "$2";
overrides your rule for:
$route['^(en|lv)/company/login'] = "login";
Try this:
$route['^(en|lv)\/(company)\/(.+)$'] = "login";
Maybe it should help you to override the first pattern
And if not, edit the first pattern to this:
$route['^(en|lv)\/(?!company).+$'] = "$2";
$route["(en|fr|gr)/(:any)/login"] = "login/index/$1";
--
public function index($company)
{
$language = strtolower($this->uri->rsegments[3]);
if(!in_array($language, ['en', 'fr'])){
// set a default language
// if the route does not provide a valid one
$language = 'en';
}
// Load the language file for the selected language
// for example english, language/en/en_lang.php
$this->lang->load($language, $language);
}
Thank you for your answer, but it seems that I didnt explain that
/company/ is controller and /login/ is "company" function. Your
solution wont work for me. :/
// The $route should contain the uri,
// you seem to have them mixed up.
// $route['uri'] = "controller/method"
$route['(en|lv)/login'] = 'company/login';
Can someone tell me, where the issue is ??
This is my controller
class Support extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('support_model');
$urlarray = array("index","delete");
if(!in_array($this->uri->segment(2),$urlarray)){
$this->viewticket($this->uri->segment(2));
}
}
public function viewticket($id){
if(!empty($id)){
$this->load->view('templates/logged_header');
$this->load->view('support/view');
$this->load->view('templates/footer');
}
}
}
Here is my routes.php
$route['default_controller'] = "welcome";
$route['benefits'] = 'welcome/benefits';
$route['faqs'] = 'welcome/faqs';
$route['distributors'] = 'welcome/distributors';
$route['contact'] = 'welcome/contact';
$route['purchase'] = 'welcome/purchase';
//login routes
$route['login'] = 'login/index';
$route['logout'] = 'login/logout';
$route['404_override'] = '';
localhost/ciproj/support/hello-world gives me 404 Page Not Found error
If I use exit; after $this->load->view('templates/footer');, the page is showing me blank page.
I don't have anything in routes related to support and every other method is working
Is there anything that i'm missing in routes ??
Thanks for the help.
Judging the title, first of all check if your server is running PHP using CGI/FastCGI or not (you could simply check that by phpinfo()).
If so, change the following in config.php:
$config['uri_protocol'] = "REQUEST_URI";
Back to the topic, you could achieve that by using the single-line route below within your routes.php file:
$route['support/(?!index)(?!delete)(:any)'] = "support/viewticket/$1";
And remove these lines from your __construct method:
$urlarray = array("index","delete");
if(!in_array($this->uri->segment(2),$urlarray)){
$this->viewticket($this->uri->segment(2));
}
Let me know how it works.
Since the above answer did not work for me, I just added this function in my default_controller, and it worked.
public function __construct() {
parent::__construct();
$this->load->helper('url');
}