Welcome Guest, Not a member yet? Register   Sign In
How can I redirect in Controller?
#1

(This post was last modified: 01-25-2018, 02:05 AM by iceleo.)

Hi,
I have a trouble, when I want to redirect to somewhere, my site is shutdowned. This is my code:

PHP Code:
return redirect('somewhere'); 

Let me know if I'm wrong.
Thanks!
Reply
#2

Skip 'return' and you are good to go.
https://www.codeigniter.com/user_guide/h...t#redirect
Reply
#3

(This post was last modified: 01-25-2018, 06:31 AM by iceleo.)

Hi Jreklund,

I'm sure you give me a document of CI version < version 4. This is CI4, this is the document of CI4 https://bcit-ci.github.io/CodeIgniter4/. Maybe, I need a help from the constructor, this is a bug, I think.

Thankyou!
Reply
#4

The way you're using it used to work, but it was reworked a bit ago and that usage might have broken. See the examples in the docs but the quick version is:

Code:
return redirect()->to('somewhere');
Reply
#5

(This post was last modified: 01-25-2018, 08:31 AM by iceleo.)

Hi,

I have test in other hosting, it works with two method redirect('somewhere') and redirect()->to('somewhere'). Maybe, I have problem with this hosting. I'm sorry about that. 

But I have another problem, the redirect always redirect to base URL. Example:

The base URL: https://mydomain.com/path/
I want redirect https://mydomain.com/path/admin to https://mydomain.com/path/admin/login if not logged in.
My redirect code is
PHP Code:
return redirect()->to('admin/login'); 
And the redirect is: https://mydomain.com/admin/login

I think I defined $baseURL correctly.

PHP Code:
public $baseURL 'https://mydomain.com/path/'

Thanks!
Reply
#6

(01-25-2018, 06:25 AM)iceleo Wrote: I'm sure you give me a document of CI version < version 4. This is CI4, this is the document of CI4 https://bcit-ci.github.io/CodeIgniter4/. Maybe, I need a help from the constructor, this is a bug, I think.
Didn't look at the sub forum on this one.
Haven't started using CI4 yet, so can't be of any help here. Sorry for popping by. :-)
Reply
#7

(This post was last modified: 10-30-2019, 06:58 AM by RobT.)

I have the same problem on CI v4.0.0rc3.

My .env file is configured as follow.
Code:
app.baseURL = 'http://localhost/path/'

My controller calls the following function.
PHP Code:
return redirect()->to('catalog'); 

I'm redirected to http://localhost/catalog instead of http://localhost/path/catalog.

How do I fix it?
Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB