Redirect Not Working CI4 |
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
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?
(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.
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
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
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.
Also if you setup your base_url correct you do not need the / forward slash.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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.
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?! |
Welcome Guest, Not a member yet? Register Sign In |