0

私が望むのは、テンプレートでフォームモデルを定義してから、フォームデータのコンテンツとしてyieldを配置することだけです. しかし、定義された各フィールドにモデル データを正しく割り当てることはできません。これは私のコードです:

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);
    }

しかし、モデル データはフォームに正しく反映されません。私の悪い英語でごめんなさい。

4

1 に答える 1

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 
于 2015-12-30T05:23:30.240 に答える