Illegal Offset in Route.php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Illegal Offset in Route.php (/showthread.php?tid=72302) |
Illegal Offset in Route.php - purpleprawn - 12-01-2018 I am currently trying to make things clean and neat and using the same endpoints for different things such as GET to /login - shows login page but POST to /login starts the login process. Going by the docs you can do this: PHP Code: $route['login'] = 'auth/login'; BUT this then throws the following error: Quote:A PHP Error was encountered I tried putting ['GET'] against the first line but didn't seem to make any difference. Any help much appreciated. RE: Illegal Offset in Route.php - Perhood - 12-03-2018 Which version of Codeigniter are you using? 3 or 4? RE: Illegal Offset in Route.php - purpleprawn - 12-03-2018 Using V3 RE: Illegal Offset in Route.php - InsiteFX - 12-04-2018 So you have a login route that's going to two different places. Remark out the first route and see what happens. RE: Illegal Offset in Route.php - dave friend - 12-04-2018 (12-01-2018, 07:16 PM)purpleprawn Wrote: I am currently trying to make things clean and neat and using the same endpoints for different things such as GET to /login - shows login page but POST to /login starts the login process. Going by the docs you can do this: I stepped through with a debugger and figured out the source of the error message. OK, these two lines are evaluated as when the file is "included". PHP Code: $route['login'] = 'auth/login'; The first line sets a value at $route['login'] which is a string. The second line tries to add an index to an array at $route['login'], but as just discussed, that value is a string. Bonk! OK, reverse the lines, eg. PHP Code: $route['login']['POST'] = 'auth/loginProcess'; No error because with this because the second line overwrites the array the previous line assigned at $route['login'] meaning $route['login']['POST'] entry is gone. The next logical thing to try is using a verb for both routes. PHP Code: $route['login']['GET'] = 'auth/login'; And this actually worked. BUT - I had to clear the browser cache to get the smarty-pants browser to do what it was told. I had originally set a test form's action to "auth/login", later to realize I really just wanted "login". But the browser kept going to the old "action" url. Had me going for a minute. Moral of the story - 1) use verbs on all associated routes and 2) clear the cache. Hope this works for you. RE: Illegal Offset in Route.php - purpleprawn - 02-11-2019 Apologies for the delay! What I think I was getting mixed up with is that if you start adding ['POST'], ['GET'] etc to the arrays then you have to carry on doing so. You can't mix and match (makes sense really!) Thanks for the help |