【问题标题】:Laravel - syntax error, unexpected ';' in bladeLaravel - 语法错误,意外';'在刀片
【发布时间】:2014-12-03 15:26:41
【问题描述】:


我的刀片有问题。我检查用户是否登录。如果是,我从 $user($user->UserName 和 $user->UserEmail)传入两个输入默认值,如果不是,我通过 Input::old()。

在我不检查用户是否登录之前,它工作正常。有什么建议吗??

观点:

@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() }}

【问题讨论】:

  • 该错误是否告诉您它认为; 出现在哪一行?
  • 我找到了这个。这是我愚蠢的错误。在 if(Auth:check()) 关闭后的输入中缺少“)”。

标签: forms laravel-4 syntax-error blade


【解决方案1】:

看起来您在表单中使用了Input 外观。

输入门面用于在您提交表单后获取表单传递的值。如果您想使用从控制器传回的旧值返回到表单,则需要将它们作为参数从控制器传递。比如:

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

您收到错误“语法错误,意外';'的原因在刀片中”是因为您在输出 Form::text() 时使用了双花括号 {{ }} 并且您在其中使用了 Input 外观,所以 php 看到的是这样的:

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

基本上,Input::old() 是在您的 Form::text() 代码中间写一个分号。

【讨论】:

  • 我找到了这个。这是我愚蠢的错误。在 if(Auth:check()) 关闭后的输入中缺少“)”。
  • 啊,很高兴你找到它!
猜你喜欢
  • 2014-06-01
  • 2021-09-16
  • 2018-04-26
  • 1970-01-01
  • 2018-01-13
  • 1970-01-01
  • 2016-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多