TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Message: simple and easy module to send short\flash messages
  • The module is used to send short messages both within the controller and the outside.

    https://github.com/WinterSilence/kohana-message

    As an example of quote controller and page feedback (a form of sending letters administrator):

    class Controller_Page_Feedback extends Controller_Page
    {
       public function action_index()
       {
          $this->view->filename('feedback');
          
          if ($this->request->post())
          {
             $form = Model::factory('Feedback', $this->request->post());
             if ($form->check())
             {
                $form->send_mail($this->config['contacts']['email']);
                
                /**
                 * Sending a successful transmission of data.
                 * The second parameter (TRUE) is used to auto translate
                 * text messages for the current language
                 */
                Message::success('Message success sent', TRUE);
                
                $this->redirect($this->request->url(), 200);
             }
             else
             {
                // Send a message with the error that occurred
                Message::error($form->errors('model'));
             }
          }
       }
    }
    
    < h2 >Feedback</ h2 >
    
    <?php if (is_string(Message::get())): ?>
    < div class="box" >
       < div class="alert alert-<?php echo Message::type(); ?>" >
          < strong ><?php echo Message::type(); ?>!</ strong > <?php echo Message::get(); ?>
       </ div >
    </ div >
    <?php endif; ?>
    
    < div class="wa-form" >
       
       < form action="" method="post" >
          
          < input type="hidden" name="csrf" value="<?php echo Security::token(); ?>" >
          
          <?php if (isset($user)): ?>
          < input type="hidden" name="email" value="<?php echo $user- >email; ?>" >
          <?php else: ?>
          < div class="wa-field" >
             < div class="wa-name" >Email:</ div >
             < div class="wa-value <?php echo Message::get('email') ? Message::type() : ''; ?>" >
                < input type="email" name="email" value="<?php echo isset($post['email']) ? $post['email'] : ''; ?>" >
                <?php echo Message::get('email') ? '< span class="help-inline" >'.Message::get('email').'</ span >' : ''; ?>
             </ div >
          </ div >
          <?php endif; ?>
          
          < div class="wa-field" >
             < div class="wa-name" >Title:</ div >
             < div class="wa-value <?php echo Message::get('title') ? Message::type() : ''; ?>" >
                < input type="text" name="title" value="<?php echo isset($post['title']) ? $post['title'] : ''; ?>" >
                <?php echo Message::get('title') ? '< span class="help-inline" >'.Message::get('title').'</ span >' : ''; ?>
             </ div >
          </ div >
          
          < div class="wa-field" >
             < div class="wa-name" >Message:</ div >
             < div class="wa-value <?php echo Message::get('message') ? Message::type() : ''; ?>" >
                <?php echo isset($post['message']) ? $post['message'] : ''; ?></ textarea >
                <?php echo Message::get('message') ? '< span class="help-inline" >'.Message::get('message').'</ span >' : ''; ?>
             </ div >
          </ div >
          
          < div class="wa-field" >
             < div class="wa-value <?php echo Message::get('captcha') ? Message::type() : ''; ?>" >
                < div class="wa-captcha" >
                   < img class="wa-captcha-img" src="/captcha/" alt="Captcha" >
                   < strong >→</ strong >
                   < input type="text" name="captcha" class="wa-captcha-input" >
                   <?php echo Message::get('captcha') ? '< span class="help-inline" >'.Message::get('captcha').'</ span >' : ''; ?>
                </ div >
             </ div >
          </ div >
          
          < div class="wa-field" >
             < div class="wa-value wa-submit" >
                < input type="submit" name="send" value="Send" class="btn grad_purple" >
             </ div >
          </ div >
       
       </ form >
       
    </ div >
    
  • Looks interesting. I'll give it a whirl.

    Shouldn't it be Kohana_Message rather than Core_Message? To keep in line with the usual inheritance pattern.

  • @samwilson i think it does't matter. this module not created Kohana community and not included in official distribution, so I did't use prefix 'Kohana'. i add reference to Kohana in description later - have problem with english =(

  • Yeah, I guess you're right. I just think it's good to stick to either Kohana or the module's own name for these 'ancestor' classes.

  • Yep. When I extend classes in the application I prefer the structure to be the same as the module's parent classes.

    module/foo/classes/Foo.php (extends Kohana_Foo)
    module/foo/classes/Kohana/Foo.php (Foo stuff)
    module/foo/classes/Foo/Bar.php (extends Kohana_Foo_Bar)
    module/foo/classes/Kohana/Foo/Bar.php (Foo_Bar stuff)
    
    application/classes/Foo.php (extends Kohana_Foo)
    application/classes/Foo/Bar.php (extends Kohana_Foo_Bar)
    

    I guess the ancestor classes don't have to use the Kohana name, but it's more readable than using the module name again (Foo_Foo, Foo_Foo_Bar) or using something unfamiliar to the Kohana community (Child_Foo, Child_Foo_Bar).

  • Yep, that's what I was getting at @papershoes. I always envisage what the names would look like if the hierarchy was collapsed together with all other modules.

Howdy, Stranger!

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

In this Discussion