J4 redirect

135 views
Skip to first unread message

Yann

unread,
Sep 26, 2022, 11:57:03 AM9/26/22
to Joomla! General Development
Hello,

I try to make a redirect in J4.
Until now, I used this code in J3 :

$app = JFactory::getApplication();
$app->redirect('index.php?option=com_component&my_view', 'message text', 'error');
$app->close();

How to make a redirect (with url + message + type message) in J4 ?

Thank in advance for your help
Yann

Viper

unread,
Sep 26, 2022, 2:09:25 PM9/26/22
to Joomla! General Development

Yann

unread,
Sep 27, 2022, 1:01:07 AM9/27/22
to Joomla! General Development
Thank you for your answer Viper.

In J3, the $app->redirect(url+msg+msg type) works everywhere. (view/hepler/controller)
In J4 the $app->redirect(url+msg+msg type) not work in controller, error below :

"An error has occurred. 0 You have not supplied a valid HTTP status code"

Based on your answer, in J4 for the redirect works in the controller with $this->setRedirect(url+msg+msg type)


Another different behaviour constated, in J3 the $app->redirect(...) support (url+msg+msg type), not in J4 (url+code redirect).

So based on this, the rules for J4 are :

-> For view/model/helper : $app->redirect(url + code redirect) and set the message system by another way.
-> For the controller : $this->setRedirect(url+msg+msg type)

If anyone have another idea, don't hesitate to share it.

Thank in advance
Yann
Reply all
Reply to author
Forward
0 new messages