1

I am slightly confused as to what the best method is of handling redirecting and displaying error/ success messages using an MVC framework, specifically Kohana.

I have a Controller User which extends the Base controller.

Am am trying to use the action_remove() function in the base controller then redirect back to the page they were on and display a message 'User has been removed....'

I don't want to pass the error message in the GET params. Is there a standard way of doing this?

tereško
  • 58,060
  • 25
  • 98
  • 150
AltDan
  • 844
  • 4
  • 13
  • 27

2 Answers2

2

You should try to use flash session data. It is very useful when You want to show errors as well as messages. At first access flash data is removed so it can be accessed only once.

http://docs.kohanaphp.com/libraries/session#flash_session_data

Also there was some related post about this here Which is the best way to display 'flash messages' in kohana v3?

Community
  • 1
  • 1
Luke Adamczewski
  • 395
  • 3
  • 14
1

You can use Message Modules in kohana 3.x. its used to display messages.

please download this module it from here and extract . Then paste it in modules folder.

https://github.com/GoldCoastMedia/kohana-flash

Then enable it in applications/bootstrap.php like as follows.

'message'      => MODPATH.'message', 

There are 5 type of messages are available. success, error, warning, info, notice. You can give styles for each messages . but you need to write class in the same name of message type.

 Message::error('pls login to access');
//to assign message type.its error message.

echo Message::display();
//to display it

thats it. but remember that you need to create class in the name of success, error, warning, info, notice to apply styles.

to check condition in view file , you can use it.

$sucessful_message=Message::display();

if($sucessful_message) { ?>
    <div id="messagedisplay" class="padding_150">
         <div class="notice_message">
            <?php echo $sucessful_message; ?>
         </div>
    </div>
<?php } ?>
jeeva
  • 1,573
  • 2
  • 15
  • 24