php - codeigniter form post from a folder inside controller not working
Get the solution ↓↓↓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?
Answer
Solution:
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 sureCSRF
either disabled or you included CSRF token in the form
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.