Redirect Not Working CI4 - 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: Redirect Not Working CI4 (/showthread.php?tid=74798) Pages:
1
2
|
Redirect Not Working CI4 - Programaciones Web - 11-07-2019 Hello Guys. I started a new Project with CI4 to see the new features and I am struggling trying to redirect between pages. It's really simple... I have a Login Controller PHP Code: <?php namespace App\Controllers; And a Dashboard Controller PHP Code: <?php namespace App\Controllers; I would like to control the User Sessions. If the user is not log in on the system... Redirect to Login View. I would like to have this functionality in all my Controllers so I just add it to the BaseController. PHP Code: protected $session; I tried everthing with (/), adding to routes of course. With only redirect(); A lot of things... but seems like something changes in CI4 that I dont get it. SYSTEMPATH/HTTP\Exceptions\HTTPException.php RE: Redirect Not Working CI4 - adelbak - 11-07-2019 I have same issue here: https://forum.codeigniter.com/thread-74736.html RE: Redirect Not Working CI4 - Programaciones Web - 11-08-2019 The only solution I found is move the Session Checker to the method Index of the Dashboard. PHP Code: <?php It's work in that way... but I will have to add this code to all index method in all my Controllers and I dont want that. I would like to have the Session Checker in the Base Controller so all Controllers will check the Session. Any way that the redirect() works from BaseController? RE: Redirect Not Working CI4 - dave friend - 11-08-2019 (11-08-2019, 01:38 AM)Programaciones Web Wrote: It's work in that way... but I will have to add this code to all index method in all my Controllers and I dont want that. I would like to have the Session Checker in the Base Controller so all Controllers will check the Session. What you need is to use Controller Filters. They were designed for doing what you ask. RE: Redirect Not Working CI4 - Programaciones Web - 11-11-2019 Still not working using filters... How do you do guys to redirect to login if user it's not logged without repeating condition in all Controllers::index? PHP Code: <?php RE: Redirect Not Working CI4 - Chivinsdev - 11-11-2019 Quote:I tried everthing with (/), adding to routes of course. With only redirect(); A lot of things... but seems like something changes in CI4 that I dont get it. This worked for me. I created url_helper.php url_helper.php then insert this code PHP Code: <?php And open the codeigniter.php replace storePreviousURL() method at line 978 with the code below PHP Code: public function storePreviousURL($uri) I hope this will help you solve your issue RE: Redirect Not Working CI4 - kilishan - 11-11-2019 There's an issue with the main url() commands that I'm trying to work out. This only happens when you're hosting in a subfolder or, like in your case, you're /public is part of your URL. It's intended that it gets served from the public directory so I never caught other cases. I imagine that's all of your issue here. However, if you want to explore an app where auth is working, you can check out my in-progress forum software, which uses my Myth:Auth lib. RE: Redirect Not Working CI4 - InsiteFX - 11-12-2019 Also if you setup your base_url correct you do not need the / forward slash. RE: Redirect Not Working CI4 - Gary - 04-18-2020 Hi, I'm trying to do the same thing with filters as suggested by Dave Friend, but even my initial experiments (to prove that the response can be messed with) of simply trying to override the return status code in an after filter isn't working. Code: class ExceptionFilter implements FilterInterface { I have the ENVIRONMENT=production for these tests (otherwise CI detailed exceptions get shown with a code trace). Could someone please explain this to me? Thanks. RE: Redirect Not Working CI4 - Gary - 04-18-2020 Ok... so if I do this: Code: public function after(RequestInterface $request, ResponseInterface $response) { I get a reponse that is reported as a 201... however, the response body is lost- all I end up with is a blank document?! |