Notice::add PHP Method

add() public static method

Add a new notice
public static add ( $type, $message = NULL, array $values = NULL ) : void
$values array
return void
    public static function add($type, $message = NULL, array $values = NULL)
    {
        $session = Session::instance();
        $notices = $session->get('notices', array());
        $notices[] = array('type' => $type, 'message' => __($message, $values));
        $session->set('notices', $notices);
    }

Usage Example

Example #1
0
 /**
  * Action login
  */
 public function action_login()
 {
     $post = $this->request->post();
     $username = Arr::get($post, 'username');
     $password = Arr::get($post, 'password');
     $remember = Arr::get($post, 'remember') ?: 0;
     // If there is post login
     if ($this->request->post('login')) {
         // ログインチェック
         if (Auth::instance()->login($username, $password, $remember)) {
             // ロールチェック
             if (Auth::instance()->logged_in('direct') or Auth::instance()->logged_in('admin') or Auth::instance()->logged_in('edit')) {
                 // Add success notice
                 Notice::add(Notice::SUCCESS, Kohana::message('auth', 'login_success'), array(':user' => $username));
                 // Redirect to home
                 $this->redirect(URL::site($this->settings->backend_name, 'http'));
             } else {
                 // Add error notice
                 Notice::add(Notice::ERROR, Kohana::message('auth', 'login_refusal'), NULL, Kohana::message('auth', 'login_refusal_messages'));
             }
         } else {
             // Add error notice
             Notice::add(Notice::ERROR, Kohana::message('auth', 'login_failed'), NULL, Kohana::message('auth', 'login_failed_messages'));
         }
     }
     /**
      * View
      */
     // Get content
     $content_file = Tpl::get_file('login', $this->settings->back_tpl_dir . '/auth');
     $this->content = Tpl::factory($content_file)->set('post', $post);
 }
All Usage Examples Of Notice::add