php - Codeigniter form_open 404 -
after searching hours still don't why 404 error when form_submit.
my controller looks this:
class pages extends ci_controller{ function view($page = 'home'){ $this->load->helper('url'); if(!file_exists('application/views/pages/'.$page.'.php')){ show_404(); } $data['title'] = $page; $this->load->view('templates/view',$data); } public function login_validation(){ } the view page:
<?php echo form_open('pages/login_validation'); echo form_input(array( 'name' => 'firstname', 'placeholder' => 'voornaam', 'class' => 'form-control input-lg', 'tapindex' => '1' )); echo form_submit(array( 'name' => 'login_submit', 'value' => 'register', 'class' => 'btn btn-primary' ));?> .htaccess (in root folder):
rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewritecond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt) rewriterule ^([a-za-z0-9_/.-]+)$ index.php?/$1 i have line in autoload.php:
$autoload['helper'] = array('form','url'); in config.php:
$config['base_url'] = 'http://localhost/'; $config['index_page'] = ''; routes.php:
$route['(:any)'] = "pages/view/$1"; $route['default_controller'] = "pages/view"; $route['404_override'] = ''; what wrong configuration?
the problem having following route (i assuming you've posted whole of routes file):
$route['(:any)'] = "pages/view/$1"; this means file load going go pages controller, call function view, , pass in parameter $1. in case, it's going pass through either 'pages/login_validation' or 'login_validation' (i'm not 100% sure which, , can't test @ moment.
your view function checking see if file 'application/view/pages/login_validation.php' or 'application/view/pages/pages/login_validation.php' exists, , when can't find it, giving 404 page.
to fix this, can add following routes.php file (above $route[(:any)] = 'pages/view/$1'; line):
$route['pages/login_validation'] = 'pages/login_validation'; that explicitly check page wanting loaded login_validation one, , call function within pages controller.
if don't want keep adding routes each time, modify view function in pages check if $page variable matches name of function, , if call function:
if (function_exists($page)) { $page(); } the trouble might have won't able pass through additional parameters given page. might accidentally name page same function in php, , try , call instead of loading page intend.
Comments
Post a Comment