Route passing $1 into the controller function instead of the value |
Hi team,
I have a new issue that is confusing me Using CodeIgnighter4, I have routes set up : $routes->get("Entry/(:any)",'Home::Entry/$1'); $routes->get("LoadEvents/(:any)",'Home::Load_Events/$l/$2'); In the Controller: public function Entry($Hive_ID,$Entry_ID){ blah blah....} public function Load_Events($BeeKeeper_ID,$mth){ echo "$BeeKeeper_ID<br>"; echo "$mth<br>"; The Entry route works without issue... (tested from the application and from postman) The Load_Events route echoes $1 as $BeeKeeper and nothing for $mth Can anyone shed some light on this behaviour ? I have tried $routes->get("LoadEvents/(:any)",'Home::Load_Events/$l'); $routes->get("LoadEvents/(:any)/(:any)",'Home::Load_Events/$l/$2'); as well to no avail... Any assistance will be appreciated.
That should explain everything: https://codeigniter.com/user_guide/incom...ior-of-any
(Yesterday, 12:16 AM)michalsn Wrote: That should explain everything: https://codeigniter.com/user_guide/incom...ior-of-any Thanks ,yes I've been through the document... according to the doc... $routes->get("LoadEvents/(:any)",'Home::LoadEvents/$l'); Should send a URI like "www.myapp.com/LoadEvents/222/333 through to Home::LoadEvents($P1,$P1).... with $P1 = 222 and $P2 = 333..... This happens correctly with other routes entries as mentioned. Except that the observed behaviour is "www.myapp.com/LoadEvents/222/333 FAILS with 2 parameters expected, 1 passed. Changing to $routes->get("LoadEvents/(:any)",'Home::LoadEvents/$l/$2); results in www.myapp.com/LoadEvents/222/333 through to Home::LoadEvents($P1,$P1).... with $P1 = $1 and $P2 = nothing The default behaviour set by routing.php public bool $multipleSegmentsOneParam = false; (Yesterday, 03:42 PM)Alex.Fry Wrote:(Yesterday, 12:16 AM)michalsn Wrote: That should explain everything: https://codeigniter.com/user_guide/incom...ior-of-any Hmmm, ok, even more confusing www.myapp.com/public/index.php/LoadEvents/222/333 works as expected.... This feels like a htaccess issue
Are you working on the local or production server?
I guess, this might be helpful: https://codeigniter.com/user_guide/insta...g-htaccess PHP Code: $routes->get("Entry/(:any)",'Home::Entry/$1'); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Routes are most flexible thing i have ever used
PHP 8.3 CI 4.6.0 PHP Code: $routes->get('{locale}/LoadEvents/(:any)', [FrontendController::class, 'LoadEvents/$1']); PHP Code: public function LoadEvents($id_1, $id_2): string 1. www.domain.com/en/LoadEvents/123/987 PHP Code: $id_1 string (3) "123" PHP Code: $id_2 string (3) "987" 2. www.domain.com/en/LoadEvents2/123/987/456/beekeeper/mnt-top PHP Code: $params array (5) (Yesterday, 10:41 PM)InsiteFX Wrote: Correct, that was small L, not integer 1 |
Welcome Guest, Not a member yet? Register Sign In |