/** * Binds the messaging system to a controller to enable `'message'` option flags in various * controller methods, such as `render()` and `redirect()`. * * @param object $controller An instance of `lithium\action\Controller`. * @param array $options Options. * @return object Returns the passed `$controller` instance. */ public static function bindTo($controller, array $options = array()) { if (!method_exists($controller, 'applyFilter')) { return $controller; } $controller->applyFilter('redirect', function ($self, $params, $chain) use($options) { $options =& $params['options']; if (!isset($options['message'])) { return $chain->next($self, $params, $chain); } FlashMessage::write($options['message']); unset($options['message']); return $chain->next($self, $params, $chain); }); return $controller; }
<?php /** * radium: lithium application framework * * @copyright Copyright 2013, brünsicke.com GmbH (http://bruensicke.com) * @license http://opensource.org/licenses/BSD-3-Clause The BSD License */ define('RADIUM_PATH', dirname(__DIR__)); require __DIR__ . '/bootstrap/media.php'; require __DIR__ . '/bootstrap/validators.php'; use radium\extensions\storage\FlashMessage; use lithium\action\Dispatcher; Dispatcher::applyFilter('_callable', function ($self, $params, $chain) { return FlashMessage::bindTo($chain->next($self, $params, $chain)); }); // use radium\models\BaseModel; // if (!BaseModel::finder('random')) { // BaseModel::finder('random', function($self, $params, $chain){ // $amount = $self::find('count', $params['options']); // $offset = rand(0, $amount-1); // $params['options']['offset'] = $offset; // return $self::find('first', $params['options']); // }); // }
protected function _message($message, array $options = array(), $key = 'flash_message') { return FlashMessage::write($message, $options, $key); }