• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I redirect in Controller?

#1
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
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');
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#5
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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