cakephp-2.0 > SessionHelper :: flash()
Search Method

SessionHelper

A AbstractTransport AclBehavior AclComponent AclInterface AclNode AclShell Aco AcoAction ActionsAuthorize ApcEngine ApiShell App AppController AppController AppHelper AppHelper AppModel AppModel AppShell Aro AuthComponent B BadRequestException BakeShell BakeTask BaseAuthenticate BaseAuthorize BasicAuthenticate BasicAuthentication BehaviorCollection C Cache CacheEngine CacheException CacheHelper CacheSession CakeEmail CakeErrorController CakeException CakeLog CakeLogException CakeLogInterface CakePlugin CakeRequest CakeResponse CakeRoute CakeSchema CakeSession CakeSessionException CakeSessionHandlerInterface CakeSocket ClassRegistry CommandListShell Component ComponentCollection ConfigReaderInterface Configure ConfigureException ConnectionManager ConsoleErrorHandler ConsoleException ConsoleInput ConsoleInputArgument ConsoleInputOption ConsoleInputSubcommand ConsoleOptionParser ConsoleOutput ConsoleShell ContainableBehavior Controller ControllerAuthorize ControllerTask CookieComponent CrudAuthorize D DatabaseSession DataSource DbAcl DbAclSchema DbConfigTask DboSource Debugger DebugTransport DigestAuthenticate DigestAuthentication Dispatcher E EmailComponent ErrorHandler ExceptionRenderer ExtractTask F File FileEngine FileLog FixtureTask Folder ForbiddenException FormAuthenticate FormHelper H Helper HelperCollection HelpFormatter HtmlHelper HttpException HttpResponse HttpSocket I I18n I18nModel i18nSchema I18nShell Inflector IniReader InternalErrorException J JqueryEngineHelper JsBaseEngineHelper JsHelper L L10n M MailTransport MediaView MemcacheEngine MethodNotAllowedException MissingActionException MissingBehaviorException MissingComponentException MissingConnectionException MissingControllerException MissingDatabaseException MissingDatasourceConfigException MissingDatasourceException MissingHelperException MissingLayoutException MissingModelException MissingPluginException MissingShellException MissingShellMethodException MissingTableException MissingTaskException MissingTestLoaderException MissingViewException Model ModelBehavior ModelTask MootoolsEngineHelper Multibyte Mysql N NotFoundException NumberHelper O Object ObjectCollection P PagesController PagesController PaginatorComponent PaginatorHelper Permission PhpReader PluginShortRoute PluginTask Postgres PrivateActionException ProjectTask PrototypeEngineHelper R RedirectRoute RequestHandlerComponent Router RouterException RssHelper S Sanitize Scaffold ScaffoldView SchemaShell Security SecurityComponent SessionComponent SessionHelper SessionsSchema Set Shell ShellDispatcher SmtpTransport SocketException Sqlite Sqlserver String T TaskCollection TemplateTask TestsuiteShell TestTask TextHelper ThemeView TimeHelper TranslateBehavior TreeBehavior U UnauthorizedException UpgradeShell V Validation View ViewTask W WincacheEngine X XcacheEngine Xml XmlException

flash

line:119 at /lib/Cake/View/Helper/SessionHelper.php
Used to render the message set in Controller::Session::setFlash()

Method

(string) public flash ($key = 'flash', $attrs = array())

Parameters

ParameterTypeCommentDefault
$key string optional The [Message.]key you are rendering in the view. 'flash'
$attrs array optional Additional attributes to use for the creation of this flash message. Supports the 'params', and 'element' keys that are used in the helper. array()

Return

string

Comment

Used to render the message set in Controller::Session::setFlash()

In your view: $this->Session->flash('somekey');
Will default to flash if no param is passed

You can pass additional information into the flash message generation. This allows you
to consolidate all the parameters for a given type of flash message into the view.

{{{
echo $this->Session->flash('flash', array('params' => array('class' => 'new-flash')));
}}}

The above would generate a flash message with a custom class name. Using $attrs['params'] you
can pass additional data into the element rendering that will be made available as local variables
when the element is rendered:

{{{
echo $this->Session->flash('flash', array('params' => array('name' => $user['User']['name'])));
}}}

This would pass the current user's name into the flash message, so you could create personalized
messages without the controller needing access to that data.

Lastly you can choose the element that is rendered when creating the flash message. Using
custom elements allows you to fully customize how flash messages are generated.

{{{
echo $this->Session->flash('flash', array('element' => 'my_custom_element'));
}}}

If you want to use an element from a plugin for rendering your flash message you can do that using the
plugin param:

{{{
echo $this->Session->flash('flash', array(
'element' => 'my_custom_element',
'params' => array('plugin' => 'my_plugin')
));
}}}

@param string $key The [Message.]key you are rendering in the view.
@param array $attrs Additional attributes to use for the creation of this flash message.
Supports the 'params', and 'element' keys that are used in the helper.
@return string
@link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash