Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
show message
  • i want to use \Message::success(...).
    but i don't how to use.

    can teach to me?
  • To do what exactly? What problem are you trying to solve?
  • this work for you if use template:

    in action set message can show in template by this code :
    action_index :
    $data = array();
    ..
    ..
    \Messages::success('success');
    return \Theme::instance()
                            ->get_template()
                            ->set('title', 'page_title')
                            ->set('menu', array('role', 'premissions'))
                            ->set('message', \Messages::get())
                            ->set('content', \Theme::instance()->view('items/create', $data));


    in template_layout :
    <?php
    if (isset($message))
    {
         foreach ($message as $msg)
         {
                 echo $msg;
         }
     }
    ?>


    but Harro I have same problem, when set message with redirect :
    action_index () {
    ..
    ...
    //load index view
    }
    action_create(){
    ..
    ..
    \Message::success(...)
    \Response::redirect('dashboard/modulename/indexaction');
    }

    I think message session flash when redirect ?
  • That depends on what Message does, where did you get it from?

    On one I made a long time ago uses flash, and has no issue with single redirects.
  • hi Harro,
    Can You Please Send Me Your Code (Message Package)?
  • No, I can't, ours is not open sourced.

    But the core of it is, you can find it in our old "depot" project: https://github.com/fuel/depot/blob/1.0/develop/fuel/app/classes/messages.php
  • hi,
    i use your file  (https://github.com/fuel/depot/blob/1.0/develop/fuel/app/classes/messages.php) and problem solved.
    please help me if my code is wrong or is better way to show message :
    for show message i use :
    if (Messages::any())
                                    {
                                        $message = Messages::get();
                                        $message = Arr::unique($message);
                                        foreach ($message as $msg)
                                        {
                                            $type = $msg['type'];
                                            if ($msg['type'] == 'error')
                                            {
                                                $type = 'danger';
                                            }
                                            echo '<div class="alert alert-' . $type . ' alert-dismissible" role="alert">'
                                            . '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'
                                            . '<span aria-hidden="true">&times;</span>'
                                            . '</button>'
                                            . '<p>&nbsp;' . $msg['body'] . '</p></div>';
                                        }
                                        Messages::reset();
                                    }

    thanks.
  • Can't say whether or not that is ok, it greatly depends on your application, and the architecture of the application.

    Our webengine is widget driven, and the messages widget uses a presenter that does the retrieval, the pre-processing, and the reset. And the HTML is a view in a theme, so that can be anything.

    All I can say is that I strongly suggest to stick to MVC architecture and Fuel's design philosophy, and not mix html and code like you do now. That prepping code should be in a Presenter (or in a controller method if you have to, and only the HTML and the foreach loop should be in the view. Mixing them will become a maintenance nightmare in the future.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion