2015-12-30 107 views
0

我只需要在模板上定义表单模型,然后将yield作为表单数据的内容。但它不能正确地将模型数据分配到已定义的每个字段中。 这是我的代码:表单模型数据在@yield上运行不正确Laravel 5

template.detail.blade.php

@extends('admin.template.lte.layout.basic') 

@section('content-page') 
    {!! Form::model($model, ['url' => $formAction]) !!} 
     @yield('data-form') 
    {!! Form::close() !!} 
    @if ($errors->any()) 
@stop 

partial.edit.blade.php

@extends('template.detail') 
@section('data-form') 
    <div class="form-group"> 
     {!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!} 
     {!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!} 
    </div> 

    <div class="form-group"> 
     {!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!} 
     {!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!} 
    </div> 

    <div class="checkbox"> 
     <label for="Dal_Active"> 
      {!! Form::hidden('Dal_Active', 'N') !!} 
      {!! Form::checkbox('Dal_Active', 'Y') !!} 
      Active 
     </label> 
    </div> 
@stop 

我的控制器部分:

 /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     $this->data['model'] = DssAlternative::find($id); 
     $this->data['formAction'] = \Request::current(); 
     $this->data['dssOptions'] = Dss::lists('Dss_Name', 'Dss_ID'); 
     return view('partial.edit', $this->data); 
    } 

但模型数据不会正确传播以形成。 对不起,我的英语不好。

回答

0

它不会工作,因为你正在过$model对象partial/edit.blade.php文件,并希望中template/detail.blade.php

正是在这一行 {!! Form::model($model, ['url' => $formAction]) !!}

解决方案使用它:template/detail.blade.php拿如此形成模型线:

@extends('admin.template.lte.layout.basic') 

@section('content-page') 
    @yield('data-form') 
    @if ($errors->any()) 
@stop 

因此partial/edit.blade.php会象下面这样:

@extends('template.detail') 
@section('data-form') 
{!! Form::model($model, ['url' => $formAction]) !!}   
    <div class="form-group"> 
     {!! Form::label('Dal_Name', 'Alternative Name', ['class' => 'required']) !!} 
     {!! Form::text('Dal_Name', null, ['required', 'class' => 'form-control', 'placeholder' => 'Enter Alternative Name']) !!} 
    </div> 

    <div class="form-group"> 
     {!! Form::label('Dal_DssID', 'DSS Period', ['class' => 'required']) !!} 
     {!! Form::select('Dal_DssID', $dssOptions, null, ['class' => 'form-control']) !!} 
    </div> 

    <div class="checkbox"> 
     <label for="Dal_Active"> 
      {!! Form::hidden('Dal_Active', 'N') !!} 
      {!! Form::checkbox('Dal_Active', 'Y') !!} 
      Active 
     </label> 
    </div> 
{!! Form::close() !!} 
@stop 
+1

感谢穆罕默德,我之前尝试,但我想概括一切为(INSERT,UPDATE)数据的形式打开和关闭结构。但没有机会.. :( –

+0

在这种情况下,只需添加另一个@yield表单头:) –