I will preface my question by saying I have searched high and low for a solution to my problem, including, but not limited to, Stackoverflow, YouTube and Google.
My issue: Only my default route is working in Codeigniter. My default route is set to a controller called Home which loads a home.php view. That works fine. I have another controller called Pages which as of now has only one method, Contact which points to view of the same name.
My routes.php file looks like this.
$route['default_controller'] = 'home/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// All custom routs go below this line.
$route['contact'] = 'pages/contact';
If I should change the default rout to 'pages/contact' my contact page shows.
My setup is as follows:
Windows 10
XAMMP 5.6.12
PHP 5.6.12
Any help would be greatly appreciated.
Default controller name should be like this $route['default_controller'] = 'home'; not like your $route['default_controller'] = 'home/home';
And then try it the url www.site.url/pages/contact is working or not if working then try
$route['contact'] = 'pages/contact';
Also you can debug your route with this link.
Related
$route['default_controller'] = 'Student';
$route['admin'] = 'index.php/Admin_depart/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I am fairly new to CodeIgniter and finishing up my first project. However, before I put it up on my hosting site I would like to clean up the URL's using the routes.php file that CodeIgniter provides in the config folder. but it is not working it work correctly when i write same url i the default_controller
The index.php is causing the issue.
Route destinations must be defined only as a controller/method pair. So in your case the correct route would be:
$route['admin'] = 'Admin_depart/index';
anyone browsing to yoursite.com/admin would be served whatever is in your Admin_depart controller, index method (just as if he/she browsed directly to yoursite.com/admin_depart/index;
How to redirect from CI default controller to HMVC modules controller?
I have a fresh installation of CI, in which I have defined default controller in /application/config/routes.php
$route['default_controller'] = 'welcome';
Now I am trying to use complete modular way and write everything in modules directory. For that purpose I have created a home app in
/application/modules/home/controllers/Home.php
Now the issue I am having is, I am not able to directly redirect to my home page using localhost/ci
This url is redirecting to default welcome.php
When I pass localhost/ci/index.php/home I can navigate to home page.
I tried using redirect, it didn't work.
I want to redirect to home page using localhost/ci url. Please help.
Change your default controller like this..
$route['default_controller'] = 'home';
if you want to redirect to particular method of your controller:Then
$route['default_controller'] = 'home/method_name';
just change your $route['default_controller'] = 'welcome';
to
$route['default_controller'] = 'folder_name/controller_name';
in your routes file.
and try
I'm new in Codeigniter framework and got routing problem.
I have Main controller and Tournaments controller.
My routes look like this:
$route['default_controller'] = 'main';
$route['main'] = 'main';
$route['tournaments/results/(:num)'] = 'tournaments/results/$1';
When I go to localhost/tournaments/results/1 and then click to link "Main" I got localhost/tournaments/results/main instead of localhost/main
What is wrong with my routes or maybe problem is somewhere else?
Probably your link to 'Main' is wrong, not your routes files. Check your link.
I am sorry if this is a duplicate but after hours of searching the interwebs i am drawing up a a blank...
I am trying to remove force all traffic to a specific controller and method so my url will read one thing but be another. the end result would be something like this:
https://www.domain.com/home/pages/about
Would become this:
https://www.domain.com/about
I have tried using the routes to no avail. Do not get me wrong, I have the default set to use that route and the main page loads just fine but sub-pages do not follow it and give a 404 error.
Default route:
$route['default_controller'] = 'home/pages';
One of the many variations I have tried:
$route['home']['pages'] = 'home/pages';
Is this possible through the routes?
I am posting this because 30 seconds before I was about to submit this I read something on another page (the codeigniter manual) that I missed before...
The fix to this is to add a custom route like follows:
$route['default_controller'] = 'home/pages';
$route['(:any)'] = 'home/pages';
That along with the default route forces all pages to use the home controller and the pages method. It gives nice pretty URL's.
If you also want to override 404's, for example you are DB powered system with base slugs in the URL:
$route['default_controller'] = 'home/pages';
$route['404_override'] = 'home/pages';
$route['(:any)'] = 'home/pages';
So, here is my problem.
In codeigniter, I have a folder inside controllers named admin and the controller admin.php inside that.
The problem is when i try posting a form from this controller to a controller outside admin folder, it does'nt works. I m really getting frustated trying to figure out where exactly i am doing wrong.
my routes.php is-
$route['admin/(:any)'] = "admin/$1";
$route['(:any)'] = "welcome/$1";
$route['default_controller'] = "welcome";
$route['404_override'] = '';
and my base url is $config['base_url'] = 'http://localhost/ci_extend/';
Actually the form is getting posted to self.
I know, surely there is routing problem but just cant figure it out. Can someone help me out?
Since you have your controller in your admin folder named admin.php
you should route it as below
$route['admin/(:any)'] = "admin/admin/index/$1";
I've included function name i.e. index , I guess the function name is required, give a hit without function name if you want to, but I don't see any problem in keeping it.
Accepted Answer
Change $route['(:any)'] = "welcome/$1"; > $route['welcome/(:any)'] = "welcome/$1"; & if using <form> make sure CSRF either disabled or you included CSRF token in the form