• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect inside Constructor NOT WORKING

(12-02-2019, 10:15 AM)kilishan Wrote: "code cleanness" can mean any number of things. For many of those definitions, Controller Filters, as previously mentioned, will keep it clean for you.

If you absolutely must do it from the constructor, you can do a slightly hacky thing and throw a RedirectException with the URL to redirect to as the message. But I highly encourage looking into controller filters, as they're specifically designed to handle the types of situations you're asking about.

Then please add this 'note' to the place where we all seem to end up, namely: typing 'redirect' into the search field of the docs and then onwards from there ...

This is the 'user experience' we get:

Search Results
Search finished, found 18 page(s) matching the search query.
  • redirect (PHP function, in Global Functions and Constants)
  • Security Guidelines
  • URI Routing
  • CodeIgniter URLs
  • Controller Filters
  • CURLRequest Class
  • Email Class
  • Error Handling
  • Global Functions and Constants
  • HTTP Feature Testing
  • Models, Views, and Controllers
  • Security Class
  • Testing Controllers
  • Version 4.0.0-alpha.2
  • Version 4.0.0-alpha.3
  • Version 4.0.0-alpha.4
  • Version 4.0.0-rc.3
  • Version 4.0.0-rc.4
Now, Controller Filters are only fifth in this list ... and it would be nice if we in the first entry; redirect ... as it takes a while to get down the list ... and usually in the process kind of lose track of what one was initially trying to achieve.

Messages In This Thread
RE: Redirect inside Constructor NOT WORKING - by blaasvaer - 09-03-2020, 01:13 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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