在Foreach语句之前查找数组键的值(Laravel 4)

时间:2014-08-15 21:04:59

标签: php arrays laravel foreach laravel-4

我的问题是我需要在开始foreach循环之前获取特定值的键。 在代码的第一行中,您看到我刚刚将$ categories []作为占位符。在我宣布表单之前,我无法启动foreach循环。否则我每次都会得到一个新表格。

这是一个表格,显示表格中的所有收入类别。如果用户选择编辑某个类别,则该页面会重新加载一个文本框和一个" Save"和"取消"只是那个类别的按钮。必须包含第一行中的参数,否则Laravel不知道要更新哪条记录。

{{ Form::open(array('route'=> array('income-category.update', $categories[]), 'method'=>'PUT')) }}
          @foreach($categories as $catId=>$catVal)
            @if($_GET['category'] == $catId)
              <tr>
                <td>{{ Form::text('category_name', $catVal) }} <br>{{ $errors->first('category_name') }}</td>
                <td>
                  {{ Form::submit('Save', ['category'=>$catId, 'class'=>'btn btn-success btn-sm', 'title'=>'Save']) }}&nbsp;
                  {{ link_to('income-category', 'Cancel', ['class'=>'btn btn-default btn-sm', 'title'=>'Cancel']) }}
                </td>
              </tr>
            @else
              <tr id="{{ 'item_'. $i }}">  
                <td>{{ $catVal }}</td>
                <td>{{ HTML::linkAction('IncomeCategoryController@index', '', ['category'=>$catId], ['class'=>'glyphicon glyphicon-pencil shadow pointer', 'title'=>'Edit']) }}&nbsp;&nbsp; {{ Form::button('', ['category'=>$catId, 'type'=>'submit', 'class'=>'glyphicon glyphicon-trash shadow pointer', 'title'=>'Delete', 'onclick' => 'confirm("For now this is just going to delete no matter what you pick.")']) }} </td>
              </tr>
            @endif
{{ Form::close() }}

0 个答案:

没有答案
相关问题