2014-12-06 63 views
0

我想插入此代码到Flash的消息,但似乎闪光灯消息不接受闪光灯消息插入PHP代码到Flash消息

<?php echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?> 
<h1>Welcome <?php echo $user->username ?></h1> 
<p>Your email: <?php echo $user->email ?></p> 
<p>Your account was created on: <?php echo $user->created_at ?></p> 
?> 


Route::post('registration', array('before' => 'csrf',function() 
{ 
    $rules = array(
     'username' => 'required|unique:users', 
     'email' => 'required|email|unique:users', 
     'password' => 'required|min:8|same:password_confirm' 

    ); 
    $validation = Validator::make(Input::all(), $rules); 

    if ($validation->fails()) 
    { 
     return Redirect::to('registration')->withErrors($validation)->withInput(); 
    } 

    $user   = new User; 
    $user->username = Input::get('username'); 
    $user->email = Input::get('email'); 
    $user->password = Hash::make(Input::get('password')); 

    if ($user->save()) 
    { 
     Auth::loginUsingId($user->id); 
     return Redirect::to('index')->with('flash_message', 'Thank you for registering. {{ echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?> 
      <h1>Welcome <?php echo $user->username ?></h1> 
      <p>Your email: <?php echo $user->email ?></p> 
      <p>Your account was created on: <?php echo $user->created_at ?></p> 
      <p><a href="<?= URL::to('profile-edit') ?>">Edit your information</a></p>}}' 
     ); 
    } 
    return Redirect::to('registration')->withInput(); 
})); 

我怎么能这样做?

我试图重新命名flash_message并把它放在这样的master.blade.php下:

@if(Session::get('login_message')) 
    <div class='login-message'>{{ Session::get('login_message') }} 
     <?php echo Session::get('notify') ? "<p style='color:green'>" . Session::get('notify') . "</p>" : "" ?> 
     <h1>Welcome <?php echo $user->username ?></h1> 
     <p>Your email: <?php echo $user->email ?></p> 
     <p>Your account was created on: <?php echo $user->created_at ?></p> 
     <p><a href="<?= URL::to('profile-edit') ?>">Edit your information</a></p> ?> 
    </div> 
@endif 

,但它没有工作,因为我想我将不得不把PHP进入路由或进入控制器。但我不知道该怎么做,我也没有宣布正确的变量。有人能帮我吗?

回答

0

您在这里混合了一些编码风格,并且您的控制器中存在您的视图元素,这是令人困惑的事情。

尝试传递要显示的刀片视图中的变量,然后使用{{ $variable }}符号将它们包括:

在你的行动,通过你的用户返回到视图:

// (snip) 
if ($user->save()) 
{ 
    Auth::loginUsingId($user->id); 
    return Redirect::to('index') 
        ->with('login_message', 'Thank you for registering.') 
        ->with('user', $user); 
} 
// (snip) 

并在视图提取用户的那些元素(这一切都在Session现在):

@if(Session::has('login_message')) 
    <div class='login-message'> 
     {{ Session::get('login_message') }} 
     <h1>Welcome {{ Session::get('user')->username }}</h1> 
     <p>Your email: {{ Session::get('user')->email }}</p> 
     <p>Your account was created on: {{ Session::get('user')->created_at }}</p> 
     <p><a href="{{ URL::to('profile-edit') }}">Edit your information</a></p> ?> 
    </div> 
@endif 

这应该可以帮助您在正确的目录挠度。

+0

它没有显示它。可能是什么原因? – Thankyou 2014-12-11 00:27:35

+0

- > with('user',$ user);不允许使用Redirect ::作为其他用户的帖子!有没有办法使用xxz :: Flash? – Thankyou 2014-12-11 13:25:43

+0

@Thankyou ..抱歉,明白你的意思了。你需要从会话以及login_message('Session :: get('user')')中提取用户。更新我的回答 – msturdy 2014-12-11 14:09:24