解释这本书如何引用你可以做到的:
如果你想改变颜色,你需要改变它们的样式。他们在书中引用的键只是向您展示了如何编写不同的 Flash 消息 - 它与消息的实际样式无关 - 只是将哪个写入位置:
//Controller
// set a bad message.
$this->Session->setFlash('Something bad.', 'default', array(), 'bad');
// set a good message.
$this->Session->setFlash('Something good.', 'default', array(), 'good');
// in a view.
echo $this->Session->flash('good');
echo $this->Session->flash('bad');
所以 - 如果你想设置不同的样式,你可以用 div 或其他东西包装“好”,并给它一个类,然后将其设置为不同的样式。发挥你的想象力 - 但关键是,键不会改变它的视觉风格,而是一个键引用它是/应该写哪个键。
我是怎么做的——使用一个元素和一个参数来改变视觉风格:
下面是我如何设置我的警报消息 - 这使用 Twitter Bootstrap 类和图标,根据我发送到我的“通知”元素的“类型”参数来改变警报的外观。当然,它可以根据您的需要进行编辑,但是您应该了解可以走的另一条路线。
$this->Session->setFlash(__('This is my success message'),
'notifications', array('type'=>'success'));
$this->Session->setFlash(__('This is my failure message'),
'notifications', array('type'=>'fail'));
//'notifications' element
<?php
$icon = 'icon-ok-sign';
if(!empty($type)) {
switch($type) {
case 'fail':
$type='danger';
case 'danger':
$icon = 'icon-warning-sign';
break;
case 'info':
$icon = 'icon-info';
break;
case 'success':
$icon = 'icon-ok-sign';
break;
case 'error':
$type = 'danger';
$icon = 'icon-warning-sign';
break;
}
}
?>
<div class="alert alert-<?php echo $type ?>">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="<?php echo $icon ?>"></i> <?php echo $message; ?>
</div>