【发布时间】:2014-07-06 21:59:30
【问题描述】:
我是 laravel 和刀片的新手。我是一名学生,正在做一个简单的“求职者”作业。我有 2 种不同类型的用户 - 求职者(第 1 类)和雇主(第 2 类)。当我从 layout.blade.php 中的按钮创建新用户时,用户将单击注册(类别 1)链接或雇主按钮(类别 2),我想将类别传递给 create.blade.php 所以我可以根据它们的类别对其进行样式化,当然还要对实际用户隐藏这些信息。
我不确定你想看什么代码,但我会从我的 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' => 'UserController@login')); }}
{{ 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' => 'UserController@create')); }}
{{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' => 'UserController@store')); }}
{{ 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 条件。即:“只是对新用户页面的测试”
提前致谢
【问题讨论】:
标签: if-statement laravel blade