douci2516 2015-09-24 00:18
浏览 24

通过控制器的简单变量显示Laravel 4.2中的错误

I am trying to pass a simple $name variable via controller.

Controller file:

if($validator->fails())
{
    $this->layout->content = View::make('admin.login' )->with('name',$name);
}

Note:

protected $layout = 'admin.layout.login_master';

$layout is class member for login page layout

View file:

@section('content')
<h1>Admin Login</h1>

                    {{ Form::open(array('url' => 'admin/login','method'=>'post')) }}
                    <div style="color:red">
                    {{ $name }}
                    </div>
                        <div id="row">
                       <div class="form-group">
                            {{ Form::label('username', 'Username') }}
                            {{ Form::text('username', '', array('class' => 'form-control')) }}
                        </div>
                        </div>

                        <div id="row">
                        <div class="form-group">
                            {{ Form::label('password') }}
                            {{ Form::password('password', array('class' => 'form-control')) }}
                        </div>
                        </div>

                        <div id="row">
                        <div class="form-group">
                            {{ Form::submit('Login',array('class'=>'btn btn-default')) }}

                        </div>
                        </div>

                    {{ Form::close() }}

@stop

it's showing an error in the log file:

Next exception 'ErrorException' with message 'Undefined variable: name (View: C:\xampp\htdocs\portfolio\app\views\admin\login.blade.php)' in C:\xampp\htdocs\portfolio\app\storage\views\94976abb04474489c25123342a2993a1:7
Stack trace:

and in the browser it's showing:

Whoops, looks like something went wrong.

  • 写回答

1条回答 默认 最新

  • dpglo66848 2015-09-24 02:16
    关注

    If this is not working, there are other ways also to pass variables from controller to view in Laravel if you have $name variable defined and want to access in views with $name then u can try any of following

    $this->layout->content = View::make('admin.login' )->withName($name);
    $this->layout->content = View::make('admin.login' )->with(compact('name'));
    $this->layout->content = View::make('admin.login', array('name'=>$name) )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程