routes.php and controllers (codeigniter) - php

I have two controllers
1- site
2- management
the first controllers(Site) is work successfuly
the second controllers(Managemnt) is not work.
I don't know what is the errror
I change the routes.php but still doesn't work(managment)
$route['default_controller'] = "site";
$route['(:any)'] = "site/$1";
$route['Administration'] = "Administration/index";
$route['Administration/([a-z])'] = 'Administration/$1';
this links work:
example.com/hotel/12312
example.com/contact
example.com/city/newyork
example.com/Administration
but this links doesn't works:
example.com/Administration/hotels
example.com/Administration/add_new
example.com/Administration/cities
where is the problem pls because I tired to solve this problem
thaks

It has to do with the order in witch you are giving route directives.
Code igniter routes requests from top to bottom, so if you want your $route['Administration'] to precede $route['(:any)'] you have to set it first.
$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";
I would allways sugest putting (:any) routes at the end so they don't overwrite more specific routes.

I had same problem & I get this working:
$route['default_controller'] = "welcome";
$route['([a-z-A-Z1-9_]+)'] = "site";
$route['management']="management";
$route['404_override'] = '';
it may help you!

I'm not familiar with Codeigniter routing, but to me looks like everything is matching $route['(:any)'] = "site/$1"; before it ever reaches your Administration routes. Try moving it below everything else...you might also have to switch your Administration routes for the ([a-z]) to match
$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";

Related

Issue routing code igniter

Hey I am having an issue routing to my other controllers in codeigniter.
Basically this is my base url http://localhost:8012/CodeIgniterProject/
This works fine but every time I type something after it I get an object not found error. I am trying to route to my Dashboard.php controller but having no luck. I want to type http://localhost:8012/CodeIgniterProject/dashboard and hit the Dashboard controller.
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['home/(:any)'] = "dashboard";
$route['(:any)'] = "";
$route['404_override'] = 'dashboard';
$route['Dashboard'] = "dashboard";
$route['about'] = "site/about";
I know this might be simple to other people but I don't usually work in php and this has me a little stumped. I was under the impression codeigniter would pick up dashboard from my controllers folder and got to my controller class to load it? And then if I wanted to pass params to the class etc I'd just need to add e.g /123??? Thanks for your time.
define method too, like:
$route['Dashboard'] = "dashboard/index";

Confused about codeigniter routes order

I'm just learning about codeigniter and am stumped by the following:
I have these routes in my routes file:
$route['(:any)'] = 'pages/view';
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['default_controller'] = 'pages/view';
Yet when i load http://mysite/index.php/news," it loads the news page rather than 'pages/view,'. I thought that because I have the catchall route at the top, this page would also just load pages/views.
Where am i going wrong?
The reason is :any doesn't match slash, at least since CI 3.0+ . So your first route rule is not a "catch all" any longer. http://www.codeigniter.com/user_guide/installation/upgrade_300.html?highlight=any#routes-containing-any
any and num is important for routing in codeigniter.
we will use any for the string value such as order001.
we will use num for the integer value such as 001.
$route['(:any)'] = 'pages/view/$1';
$1 is define for the first parameter.
$route['(:any)/(:any)'] = 'pages/view/$1/$2';
for 2 parameter pass in url.

Tank_Auth With Code Igniter Giving 404 on registration-success

I'm working with CodeIgniter and Tank_Auth. I got the registration to work, but it looks like it's trying to load registration-success, and I'm not sure where that is.
In auth.php on line 239 I have
$this->tank_auth->notice('registration-success');
I see a registration-success.php in views/landing/registration-success.php. Is this the page it's trying to access? I'm getting a 404 when I submit a successful registration (I can see the user created in the db).
EDIT:
After resetting and updating my routes.php file, I see that I'm getting a 404 page not found error while the url in the browser points to index.php/auth. Is there something I'm supposed to route in order for this to work?
Currently I have the following in my routes.php:
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['login'] = "/auth/login";
$route['logout'] = "/auth/logout";
$route['register'] = "/auth/register";
I am looking at TA library and I don't see any notice() method or function. Also in auth.php (fresh download) I did not find any lines that contain "notice".
Also note
that you have two $route['default_controller'] in your routes.php.
that routing in CodeIgniter is prioritized.
Your config/routes.php should look like.
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['login'] = "/auth/login";
$route['logout'] = "/auth/logout";
$route['register'] = "/auth/register";
$route['(:any)'] = 'pages/view/$1';
see the last line ? it uses a "wild card", you had problem with that line because, it grabbed eg. localhost/project/login and "redirected" (routes do not redirect) to localhost/project/pages/view/login terefore you got 404

codeigniter routes issue for main url

I have defined a new route on routes.php but it have problem.
$route['default_controller'] = "index";
$route['404_override'] = '';
$route['(:any)'] = "oyna/oyun/$1";
I want to redirect /2012.htm to oyna/oyun/2012.htm and I can but it create a new problem. I can't reach my other controller if I don't define as below:
$route['default_controller'] = "index";
$route['404_override'] = '';
$route['admin/(:any)/(:any)'] = 'admin/$1/$2';
$route['admin/(:any)'] = 'admin/$1';
$route['kategori/(:any)'] = "oyna/kategori/$1";
$route['(:any)'] = "oyna/oyun/$1";
If i don't define any controllers on routes.php like above I can't reach that.
What i need to do for solve?
I'm not sure, but try to replace $route['(:any)'] = "oyna/oyun/$1"; with $route['(:num).htm'] = "oyna/oyun/$1.htm";
Or better: $route['(\d+).htm'] = "oyna/oyun/$1.htm";
CodeIgniter's routes are a little funny, but once you understand how they're processed, it makes perfect sense.
Since routes use regular expression matching, you can't just have something super generic and expect everything else to work, because it's going to look at routes before simply routing to the controller/method implied by the URL.
If you want to match URLs such as http://domain.tld/2njkf4r AND http://domain.tld/pages/about then you will have to create more specific rules to handle "exceptions" to the very general rule that will match the first case.
You are correct that it won't work unless you define the other routes, because with only $route['(:any)'] as a route, EVERY request will match that. That route has to be your absolute last route. It's a pain in the ass, but necessary, because of the way they process routes.
My all links have .htm at end's. And this is the solve:
$route['(:any).htm'] = "oyna/oyun/$1";
Because my controllers haven't got .htm at the end.

Codeigniter Routing remove controller

I want to route so that the "domain" part dissapears,
http://www.domaininfo.za/domain/google.com
to something like this
http://www.domaininfo.za/google.com
I have managed to remove the welcome part but how do i remove domain?
my route file:
$route['default_controller'] = "welcome";
$route['404_override'] = '/';
$route['(:any)'] = "welcome/domain/$1";
Not sure if this is what you're asking, but does this work for you?
$route['(:any)'] = "domain/$1";
Your routing is dangerous...I would put a regex in the route key to recognize web domains, then route it to welcome/domain/$1. Right now you are routing all values in the controller space to welcome/domain/$1. Mod-rewrite or using regex in your router would be best.

Categories