2014-10-08 30 views
0


我有刀片問題。我檢查用戶是否登錄。如果我從$ user($ user-> UserName和$ user-> UserEmail)傳遞兩個輸入默認值,如果不是,則傳遞Input :: old()。

Laravel - 語法錯誤,意外';'在刀片上

在我不檢查用戶是否登錄之前,它工作正常。有什麼建議麼??

的觀點:

@if($errors->has()) 
    <ul> 
     @foreach ($errors->all() as $error) 
      <li class="txt-danger">{{ $error }}</li> 
     @endforeach 
    </ul> 
@endif 

@if(Session::has('message')) 
    <ul> 
     <li class="txt-success">{{ Session::get('message') }}</li> 
    </ul> 
@endif 

{{ Form::open(array('url'=>'contact', 'name'=>'contactform', 'id'=>'contactform')) }} 
    <p> 
     @if(Auth::check()) 
      {{ Form::text('name', $user->UserName, array('id'=>'name') }} 
     @else 
      {{ Form::text('name', Input::old('name'), array('id'=>'name', 'placeholder'=>'Twoje imię')) }} 
     @endif 
    </p> 
    <p> 
     @if(Auth::check()) 
      {{ Form::text('email', $user->UserEmail, array('id'=>'email') }} 
     @else 
      {{ Form::text('email', Input::old('email'), array('id'=>'email', 'placeholder'=>'Twój e-mail')) }} 
     @endif 
    </p> 
    <p> 
     {{ Form::text('subject', Input::old('subject'), array('id'=>'subject', 'placeholder'=>'Temat')) }} 
    </p> 
    <p> 
     {{ Form::textarea('message', Input::old('message'), array('id'=>'message', 'placeholder'=>'Wiadomość', 'rows'=>'0')) }} 
    </p> 
    {{ Form::submit('Wyślij wiadomość', array('class'=>'mainBtn', 'id'=>'submit')) }} 
{{ Form::close() }} 
+0

錯誤是否告訴你它認爲';'出現在哪一行? – 2014-10-08 21:26:01

+0

我找到了。這是我愚蠢的錯誤。在if(Auth:check())閉包失蹤後輸入「)」。 – Marcin 2014-10-08 22:00:13

回答

0

它看起來像您使用的表單中的Input門面。

輸入外觀用於在提交表單後獲取表單傳遞的值。如果您想要使用從控制器傳回的舊值返回到窗體,則需要將這些值作爲控制器的參數傳遞。例如:

return View::make('MyView')->with('old', $oldValues); 

您收到錯誤「語法錯誤,意外錯誤」的原因;''在刀片」是因爲你使用雙大括號{{ }}當你輸出的Form::text()並且正在使用中它Input門面,還等什麼PHP是看到的是這樣的:

echo "<input type='text' name='email'> valuefrominput;</input>"; 

基本上,Input::old()是在你的Form::text()代碼中間寫一個分號。

+0

我找到了。這是我愚蠢的錯誤。在if(Auth:check())閉包失蹤後輸入「)」。 – Marcin 2014-10-08 22:00:31

+0

啊,我很高興你找到了! – 2014-10-08 22:37:53