2014-05-19 53 views
0

我是laravel和blade的新手。我是一名做一个简单的'求职者'任务的学生。我有两种不同类型的用户 - 求职者(1类)和雇主(2类)。当我从layout.blade.php中的按钮创建一个新用户时,用户将点击一个注册(类别1)链接或雇主按钮(类别2),我想将类别传递给create.blade.php我可以根据它们的类别对它进行风格化,当然也可以将这些信息从实际的用户中隐藏起来。@if声明使用URL参数laravel blade

我不知道你想看到什么样的代码,但我会用我的layout.blade.php开始 - 单击链接或按钮时,它重定向到create.blade.php和URL更新无论是第1类还是第2类 - 取决于点击的内容。我想为它创造被显示,一个求职者或一个雇主增加一个@if语句(它们具有略微不同的选项)

layout.blade.php

<div class="col-sm-9"> 
@if (!Auth::check()) 
<div class="login-form"> 
{{ Form::open(array('action' => '[email protected]')); }} 
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }} 
{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }} 
{{ Form::submit('Sign in', array('class' => 'btn btn-danger')); }} 
{{ Form::close(); }} 
{{ Form::open(array('action' => '[email protected]')); }} 
{{link_to_route('user.create', 'or Register here', ['category' => 1])}} 
</div> 
{{link_to_route('user.create', 'Employers', ['category' => 2], array('class' => 'btn btn-primary')) }} 
@endif 
@yield('content1') 

create.blade.php

@extends('job.layout') 
@section('content1') 
@if('category' == 2) 
<h1>New Employer page</h1> 
{{ Form::open(array('action' => '[email protected]')); }} 
{{ Form::text('username', null, array('class' => 'input-small', 'placeholder' => 'Email')); }} 
<p>{{ Form::password('password', array('class' => 'input-small', 'placeholder' => 'Password')); }} 
{{ Form::hidden('category', 2) }} 
{{ Form::label('name', 'Name:', array('class' => 'col-sm-3')) }} 
{{ Form::text('name') }} 
{{ Form::label('description', 'Company Description:', array('class' => 'col-sm-3')) }} 
{{ Form::text('description') }} 
{{ Form::label('industry', 'Industry', array('class' => 'col-sm-3')) }} 
{{ Form::text('industry') }} 
{{ Form::label('phone', 'Phone Number:', array('class' => 'col-sm-3')) }} 
{{ Form::text('phone') }} 
<p>{{ Form::submit('Sign in'); }} 
{{ Form::close(); }} 
@else 
<p>just a test for New User Page 
@endif 
@stop 

到目前为止的创建页面只会导致返回@else条件。即:提前

回答

0

我会尽量避免所有的代码,因为你是使它方式复杂得多,它是“只是一个测试新的用户页面”

感谢。

我会一步一步解释。

提出两个意见。一个是求职者,一个是雇主。

取决于类别,加载相应的视图。这就是你想要的。

让我们来代码。

routes.php文件

Route::get('create/{category}', array(
        'as'  =>  'create', 
        'uses'  =>  '[email protected]' 
         )); 

UserController的

public function create($category) 
    { 
     if($category==1) 
      return View::make('seeker'); 
     elseif($category==2) 
      return View::make('employer'); 
     else 
      App::abort(400); 

    } 

就是这样。无需触摸布局。尽可能避免将逻辑放在布局中。从长远来看,这将是一团糟。

+0

我打算做出2个单独的视图,因为这样做比试图用1更有意义。我认为我的任务只允许我创建1'创建'视图。会按照你的方式去做,并看看我走了。谢谢 :-) – AngeKing