I'm working with HMVC with wiredesignz plugin and have the following url mysite.com/login and it views my login form. I have the form to post to the submit method in the login controller inside of the user module. I'm trying to figure out what the route would be for this to work because inside of the submit method I have it echoing a string for testing purposes. The first route works beautifully but the second route presents a 404 Page not found. Any thoughts on how to correct this.
$route['login'] = 'user/login';
$route['login/submit'] = 'user/login/submit';
Try this one
$route['login/(:any)'] = 'user/login/$1';
$route['login'] = 'user/login';
or try to change the action of form to submit
$route['submit'] = 'user/login/submit';
$route['login'] = 'user/login';
I was able to fix my issue by noticing that my submit function was named as a private function and not listed as public.
Related
I am having entry in my route.php like - $route['admin/students'] = 'view_student'. Here view_student is controller name. Now when from "localhost/school/admin" page I call Students, than everything works fine; But when I change my route like - $route['/school/admin/students'] = 'view_student', and call it from "localhost/school/admin" page as Students, than 404 page is shown. Whats wrong in here?
Try this code it might help you :
Here dashboard is the name of controller
//this will route as localhost/appFolder/admin/index
$route['admin'] = 'dashboard'; // for your index page
//this will route as localhost/appFolder/admin/method_name
$route['admin/(:any)'] = 'dashboard/$1';
//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';
Link the route Like
// for your index page
// for your other pages
To link the other controller defined just like
school is your ci root, so if you define $route['/school/admin/students'], it will seek school class with admin function, that never exist, instead of admin route.
you should read the documentations first before make any step,
https://www.codeigniter.com/userguide3/general/routing.html
i have
$route['administrator/(:any)'] = "$1";
where i want to bypass administrator and load method and function in codeigniter 3.0.4 but get 404 page not found actually what i want to do is i have a member class with login function and i what want to show login just like administrator/member/login url can any one help me to route in such way as well as any other class respectively administrator/method/function
If you want to use this URL:
administrator/member/login
Than you can define as:
$route['administrator/member/login'] = "yourClassName/yourFunctionName";
If you have any additional param, than you can use it as slug:
$route['administrator/member/login/(:any)'] = "yourClassName/yourFunctionName/$1";
Note that, if administrator is your project name than remove it from route as:
$route['member/login'] = "yourClassName/yourFunctionName";
CI URI Routing
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
How can I remove controller name from url . I have two controller
home and admin
and the url's are
http://domain.com/likes/home/post/sports/20-Athletes-Who-Profited-While-in-College-/12
home/post
and
http://domain.com/likes/admin/ad_managment/edit/2
http://domain.com/likes/admin/meta_tags_home/edit/2
admin/ad_managment admin/meta_tags_home
I have already used this
$route['(:any)/(:any)/(:num)'] = "home/post/$1";
It works for this URL
http://domain.com/likes/home/post/sports/20-Athletes-Who-Profited-While-in-College-/12
admin is not working. Basically I want to remove home/post Leave admin controller it doesn't matter
try this
$route['(:any)/(:any)/(:any)'] = "home/post/$1";
Try this example
$config['base_url'] = 'http://your-site.com/';
And in your routes.php
$route['default_controller'] = 'main';
Through this method you can remove controller name from url.
check user guide of codeigniter and in this example see how the routing done.
Read more about code-igniter routing
I have a small problem with routing.
My routes:
$route['category/(:any)/(:num)'] = "site/index/$2"; //not working
$route['category/(:any)'] = "site/index"; //not working
$route['category/(:any)/(:any)'] = "site/view/$2"; // working
$route['Search'] = "site/search"; // working
What I want: http://example.com/category/Home - call site/index function
http://example.com/category/Home/2 call site/index function with parameter $2
I'm geting 404 erro at those 2 rules.
What I tried was to echo the parameter of category/(:any)/(:num) and it echoed it. This echo was inside the index function. The views adn models exists in the paths I declared. The index page itself wouldn't work without it. So I think the problem has to be in routing
The most interesting thing is that when I change the category/(:any) route to site/view it is working but when I set there site/index it is not working. Even if I set there only site .
I think what you are trying to do is to have your site class as "default controller". Just try this :
$route['default_controller'] = "site";
$route['(:any)'] = "site/view/$1";
$route['(:num)'] = "site/index/$1";
I don't really know what you are trying to do with your site/view/$1 and site/index/$1 it will work like this :
example.com/someaction will match $route['(:any)'] and will call the view method of the site controller with someaction as a string parameter.
example.com/2 will match $route['(:num)'] and call the index action of the site controller with 2 as an integer parameter.
example.com/admin will call the index action of the admin controller
example.com/admin/category will call the category action of the admin controller