-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with redirects - had to use exit to make it work and blank page #1501
Comments
Ok, the oldInput changes have been reverted, and the unit tests show that bug. |
Hmm - after setting the baseURL & indexPage properties in App, I get a blank page even for .../home, |
@jim-parry - no sorry redirect still doesn't work and I kind of rely on redirects to get to edit form page to do the testing for old(). Just for clarification, I updated my local copy again just now. Also, I seem to have found another issue which wasn't there before but I need to investigate more what this new issue is and why I am getting this exception all of sudden as yesterday it was working. Could it be linked to that redirect issue?
I actually update my local copy everyday using git pull and everything except old() bug worked fine. I can confirm that this issue only started after I did git pull today after seeing your comment that it;s fixed. |
Very strange. |
Very strange indeed. The reason I am so sure about that it stopped working today is, as I mentioned above, that I published my local site yesterday. My server copy isn't synced to my local as I manually ftp the changes as of now. |
And, because I went live, for that very reason I was doing some tests today on Sunday otherwise I wouldn't have bothered checking on a weekend. |
@daljit3 I think this should solve both the redirect problem here, as well as the original old() issue. |
@jim-parry Yes just tested again:
However, now I see another issue (Sorry Jim! :p) Also wondering what was the issue with redirects? |
@daljit3 When you call the You can check if has errors with |
The redirect issue was caused by my dropping the sendHeaders(), to address a different bug :-/ |
Solution confirmed |
@jim-parry hi - it seems like redirects are ending on blank again!! Just updated my local copy today. |
You update daily, so they were working yesterday and now not today? |
I was working on a different project so I hadn't updated for the past couple of days. I just did and it went blank. |
i'm trying to isolate "when" this broke. so, sometime in the last couple of days... |
Okay - if you want me to do any quick tests - I am available here for another hour and half. Please let me know. |
The biggest help would be a unit test case that fails when it shouldn't. It is obvious to me that the ones we have now are missing the boat - they are not catching the problem, even I thought we caught it last week. There could be several things happening here. |
I'll look and see if I know how to set that up on my local. The exception error is back too! :( |
I just ran php unit test and I get 105 failures but if I tried vendor\bin\phpunit --filter CommonFunctionTest I get "No code coverage driver is available". I might not have got it config properly? |
to run just the one test, vendor/bin/phpunit tests/system/CommonFunctionsTest.php |
@daljit3 Please, check if you have the PHP |
With the latest code, I tried the following code, navigated to
That makes me think it's less a bug and more a configuration error on your app, or something? Can you provide exact code you're able to replicate it on, and tell us what the exception is that's showing up? |
@lonnieezell @natanfelles @jim-parry I think I have found what's causing issue for me. As mentioned before,
To fix this issue, I have to replace with The bizzare thing is that both option worked for me with after @jim-parry fix and it only stopped since I raised this once again. Here's my quick and dirty test with results on a fresh installation today at 09:30 AM 23/11/2018.
|
You can no longer use .dev for localhost use .local These changes were made in chrome and other web browsers. |
@InsiteFX yes I am aware of that and that's not the issue. |
Ah, ok, I see what's going on and looks like docs will take care of most of it. Suggestions after the break:
Here's what I see is needed to fix this up:
|
@lonnieezell yes that makes sense however please take a look at this test below ... It doesn't redirect to login but just displays the text "You are here because you are logged in". That's incorrect. It should have redirected to /home/login. The other tests 1 to 5 above still seem to work OK so can't figure out what's going wrong with this one. I tested this is on fresh installation which I downloaded few mins ago.
|
You must return to stop the script: public function test6() {
if(isUserLoggedIn() == false) {
RETURN redirect()->to('/home/login/?ref='.'$refUrl');
}
echo "You are here because you are logged in!";
} |
I have that return set up in redirectIfNotLoggedIn(); ?? Will this not work? I had it working fine when |
@natanfelles Sorry if I wasn't clear but are you referring to @lonnieezell on my old method of using redirect/exit? I have all the redirects now with the returns. I am trying to understand why the below isn't redirecting. I am returning in the
|
To complete: You must return in the Controller method as well. Like the example I gave you. I used only part of your functions because they do not allow it to be used consistently. |
I may be wrong but I am not convinced I need to return from controller too? I mean I expect the redirect to happen when user is not signed in inside redirectIfNotLoggedIn() method and otherwise just continue. I can surely achieve that using different logic e.g. the way you suggested i.e. in the controller. However, I need to check that at various diffrent points so I would end up repeated If/Else checks throughout my project or perhaps I will end up writing my own redirect helper.
|
Yes. It continues, because it returns a RedirectResponse (as the Lonnie's comment explain). It will not You could to use your custom |
I just feel the correct behaviour is that it should redirect() from redirectIfNotLoggedIn() when the condition fails as it's still being called in from a controller method. |
Here's the code in question, right?
While At this point, we're dealing with a support issue, and not a bug. If you still have questions, please take it to the forums. I'm only leaving this open to remind us that we have a few things (listed above) that we need to take care of. |
Yes understand. Thanks |
@daljit3 Are you using "php spark serve" for local development and do you have a filter (FilterInterface) in your code? I'm going on a hunch here. |
Hi, I'm currently migrating my old CodeIgniter code. The |
Well - this isn’t old CodeIgniter so that parts not helpful :) We’ve gone over and over this and I’m pretty sure it’s solid at this point. Can you provide a code sample? If I had to take a blind guess it’s that you’re trying to redirect out of a controller constructor and that doesn’t work any longer. You should check out Controller Gilters in the docs. |
Hi, thanks lonnieezell for pointing it out. I just did a bit of test and found that the return works on function that's not constructor. I read about the Controller Filters but couldn't found out how to intergrate my variables in constructor to the Filters so for now I'll just use the exit() for workaround. |
experiencing this problem too.
this worked for me! |
Hi. In this case you may use Filters. See that example https://www.patreon.com/posts/visit-logging-27277581 |
The redirect functions were not working. thats wat i needed, the filters will not do. in my admin controller i use a library with some checks. it wil update my routes file and will redirect me to the admin controller again from within my library. Here the redirect->to(current_url()) is not working and it just keeps executing the code but it should redirect with a refresh to the same url. adding this works: |
You who are having issues still, are you remembering to return the result of |
I'm having issues with this as well in the latest version... |
I am facing the same problem. These don't work.
However when I use it with response, it works
As suggested above this too works:
Can this be an issue related to .htaccess?
|
I also faced the same issue, but i was able to solve it . i belive it an mistake in the routes file or the redirection url. |
name: Bug report
about: Help us improve the framework by reporting bugs!
Describe the bug
There are two issues with the
redirect()
method.return redirect()->to('/');
so I have to follow it up with an exit to make it work. e.g.mylocalsite/home/daljit
it just shows a blank page.CodeIgniter 4 version
CodeIgniter 4 develop branch.
The text was updated successfully, but these errors were encountered: