Validator, captcha, form, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@141 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
50
view/helpers/MsgViewHelper.php
Normal file
50
view/helpers/MsgViewHelper.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
|
||||
class MsgViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
const SUCCESS = 'success';
|
||||
const ERROR = 'error';
|
||||
|
||||
protected $get;
|
||||
|
||||
public function msg($msg = null, $type = null)
|
||||
{
|
||||
if ($msg && $type) {
|
||||
if (!in_array($type, array(self::SUCCESS, self::ERROR))) {
|
||||
throw new Exception('Unknown message type: "' . $type . '"');
|
||||
}
|
||||
Session::set(__CLASS__, array('message' => $msg, 'type' => $type));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function success($msg)
|
||||
{
|
||||
Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS));
|
||||
}
|
||||
|
||||
public function error($msg)
|
||||
{
|
||||
Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR));
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$msg = Session::get(__CLASS__, false);
|
||||
if ($msg) {
|
||||
Session::del(__CLASS__);
|
||||
return '<div class="' . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>';
|
||||
}
|
||||
return ' ';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user