• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Illegal Offset in Route.php

#5
(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: 

PHP Code:
$route['login'] = 'auth/login';
$route['login']['POST'] = 'auth/loginProcess'

BUT this then throws the following error:

Quote:A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'POST'
Filename: config/routes.php
Line Number: 57

I tried putting ['GET'] against the first line but didn't seem to make any difference. Any help much appreciated.

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';
$route['login']['POST'] = 'auth/loginProcess'

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'
$route['login'] = 'auth/login'

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';
$route['login']['POST'] = 'auth/loginProcess'

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.
Reply


Messages In This Thread
Illegal Offset in Route.php - by purpleprawn - 12-01-2018, 07:16 PM
RE: Illegal Offset in Route.php - by Perhood - 12-03-2018, 05:59 AM
RE: Illegal Offset in Route.php - by purpleprawn - 12-03-2018, 06:34 PM
RE: Illegal Offset in Route.php - by InsiteFX - 12-04-2018, 05:28 AM
RE: Illegal Offset in Route.php - by dave friend - 12-04-2018, 12:37 PM
RE: Illegal Offset in Route.php - by purpleprawn - 02-11-2019, 06:27 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.