CodeIgniter Forums
when I set routes with add and post, It's not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: when I set routes with add and post, It's not work (/showthread.php?tid=80051)



when I set routes with add and post, It's not work - asrahi - 09-07-2021

Hi!
I was setting $routes like this,
But it's not work
I expected, if I connect "test.com/board" then call Board:list
and I try to submit form POST in "test.com/board", as I know it's call BoardConfusedearch.

I was trying to modify my code to priority, as, and something else...
but it's not work too

filnaly I figure out, if Im trying to use "get" instead of "add", then It's work..  Huh
I couldn't understand well
plz tell me this problem

Thank you


PHP Code:
$routes->group('board',function($routes){
 
$routes->add('(:any)/view/(:num)''Board::read/$1/$2');
 
$routes->add('(:any)/read/(:num)''Board::read/$1/$2');
 
$routes->add('(:any)/read/(:num)/(:any)''Board::read/$1/$2/$3', ['as'=>'board_read']);

 
$routes->add('(:any)/write''Board::write/$1/$2');
 
$routes->add('(:any)/write/(:any)''Board::write/$1/$2', ['as'=>'board_write']);

 
$routes->add('(:any)/edit/(:num)''Board::edit/$1/$2');
 
$routes->add('(:any)/edit/(:num)/(:any)''Board::edit/$1/$2/$3', ['as'=>'board_edit']);

 
$routes->add('(:any)/closed''Board::block/$1');
 
$routes->add('(:any)/closed/(:any)''Board::block/$1', ['as'=>'board_block']);

 
$routes->add('(:any)/del/(:num)''Board::del/$1/$2', ['as'=>'board_del']);

 
$routes->post('(:any)/post''Board::post/$1', ['as'=>'board_post']);
 
$routes->post('(:any)/replyPost''Board::replyPost/$1', ['as'=>'board_reply']);

 
$routes->post('(:any)''Board::search/$1',['priority'=>1]); //예약조회 등등
 
$routes->add('(:any)''Board::list/$1',['as'=>'board_list''priority'=>10]); //리스트

});
$routes->addRedirect('board','/'); 




RE: when I set routes with add and post, It's not work - ikesela - 09-07-2021

better use 'get' instead 'add' , so router know what to do, not guessing what to do using 'add'

* from CI documentation: it is recommended to always use the HTTP-verb-based routes


RE: when I set routes with add and post, It's not work - kilishan - 09-07-2021

Using `add` will make the route available across ALL verbs (get, post, etc). It is always better to specify the exact verb you want used so that there's no unintended actions happening when a different verb gets used. While there's a very small chance that could form a security issue, it does cause issues like you were just seeing, also.


RE: when I set routes with add and post, It's not work - asrahi - 09-09-2021

(09-07-2021, 12:48 PM)ikesela Wrote: better use 'get' instead 'add' , so router know what to do, not guessing what to do using 'add'

* from CI documentation: it is recommended to always use the HTTP-verb-based routes

Thank you! I'll use 'get'
Actually I can't understand well documentation, bcz I can't speak english well ;(

(09-07-2021, 12:58 PM)kilishan Wrote: Using `add` will make the route available across ALL verbs (get, post, etc). It is always better to specify the exact verb you want used so that there's no unintended actions happening when a different verb gets used. While there's a very small chance that could form a security issue, it does cause issues like you were just seeing, also.

Thank you!
I wonder, why the 'post' (written explicitly) can't has priority? even I set attribute of priority


RE: when I set routes with add and post, It's not work - InsiteFX - 09-10-2021

If your using chrome or any new web browser most have a language translation built in now.