Welcome Guest, Not a member yet? Register   Sign In
Redirect - pass message to next page
#1

(This post was last modified: 12-22-2020, 12:05 PM by BFlokstra.)

Not sure if this is in the right place....

I need to perform a redirect after a database action (delete). I have added the folowing line: 
return redirect()->to('/evenementen/' . url_title($evenement['evenement_naam'], '-', TRUE));

On evenementen/evenement_name I need a specific message to be shown ("The event was succesfully removed"). Is there a specific CI4 way to do this nicely of should I just add a query to the url? (?m=the_message)

I'm pretty new to CI in general, coming from php without any frameworks, so forgive me if this is a "stupid" question ;-)
Reply
#2

Try adding "with('message')" like this:
PHP Code:
return redirect()
    ->to('/evenementen/' url_title($evenement['evenement_naam'], '-'TRUE))
    ->with('message'"The event was succesfully removed"); 

Then in your view, you can output the message like this:
PHP Code:
<?php if (session('message') !== null) : ?>
    <?= session('message'); ?>
<?php 
endif; ?>
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

Thanks! This worked perfectly. And with a little tweaking I even managed to pas along different types of messages (errors and success messages)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB