我根据提供给这个问题的答案按照指示做了但它对我不起作用.所以我又问了这个问题。我的控制器是
public function save() {
$med_group = MedicineGroup::create(Request::all());
if ($med_group) {
$this->setServerMessage('MedicineGroup created successfully');
return Redirect::to('admin/user/create')->with('flashmessage',$this->getServerMessage());
}
}
我已经在控制器中制作了setServerMessage()和getServerMessage(.php
public function setServerMessage($messagearray) {
if (is_array($messagearray)) {
$type = $messagearray['type'];
$html = "<div style='height:auto;padding:7px 0px 6px 20px;margin:0px' class = 'pull-left text-left col-md-8 alert alert-{$type}'>{$messagearray[0]}</div>";
} else {
$html = "<div style='height:33px;padding:7px 0px 6px 20px;margin:0px' class = 'pull-left text-left col-md-8 alert alert-info'>{$messagearray}</div>";
}
$temp = '';
if ('Session::get('SERVER_MESSAGE')) {
$temp = 'Session::get('SERVER_MESSAGE');
}
'Session::put('SERVER_MESSAGE', $temp . $html);
}
public function getServerMessage() {
if ('Session::get('SERVER_MESSAGE')) {
$temp = 'Session::get('SERVER_MESSAGE');
'Session::forget('SERVER_MESSAGE');
return $temp;
} else
return "";
}
我的视图是这样设置的
<div class="box-footer text-right">
@include('flash')
<input type="submit" class="btn btn-success" value='Save'>
<input type="reset" class="btn btn-primary" value='Reset' />
<a href="#" class="btn btn-danger">Cancel</a>
</div>
在我的闪光刀片中.php我写了
@if(isset($flashmessage))
{!! $flashmessage !!}
@endif
我错过了什么? 我也关注了这个网站,但我无法在我的视图中闪烁消息。
设置闪存消息,然后重定向到所需的路由
控制器:
session()->flash('msg', 'Successfully done the operation.');
return Redirect::to('admin/user/create');
现在获取消息"视图中的边栏选项卡"
叶片
{!! Session::has('msg') ? Session::get("msg") : '' !!}
试试这个东西,我正在替换你的整个代码,你可以根据需要进行更改:
public function save()
{
$med_group = MedicineGroup::create(Request::all());
if ($med_group) {
//$this->setServerMessage('MedicineGroup created successfully');
// flash method to be used when just printing the message
// on the screen. Link below
'Session::flash('key', 'Your message here...');
return Redirect::to('admin/user/create');
}
}
在视图文件中:
@if(Session::has('key))
{{ Session::get('key') }}
@endif
更多信息链接
every other thing seems to be fine except for your layout
laravel would escape the variable you are passing into the session while using this
@if(isset($flashmessage))
**{!! $flashmessage !!}**
@endif
you should do this instead
@if(isset($flashmessage))
**{{ $flashmessage }}**
@endif