我有一个页面,其中包含儿童团体。 每个集团都需要具有特定的渲染(具有特定的模板)。 为此,我必须在刀片模板中使用@php。
这是我的代码:
PageController.php
public function edit(Page $page)
{
return view('pages.edit', compact('page'));
}
查看页面/edit.blade.php
<section id="contents" class="contents ui-sortable">
@foreach ($page->blocs as $bloc)
@php
echo $bloc->id;
echo App\Http\Controllers\BlocController::renderBloc($bloc);
@endphp
@endforeach
</section>
BlocController.php
public static function renderBloc(Bloc $bloc) {
echo $bloc->id;
return view('blocs.show.' . $bloc->bloc_type, [
'bloc' => $bloc,
'data' => json_decode($bloc->data)
]);
}
然后是集团的一个例子
资源/视图/blocs/show/text.blade.php
@extends('blocs.show')
@section('bloc')
{{ $bloc->id }}
@endsection
资源/视图/blocs/show.blade.php
<section class="bloc bloc_{{ $bloc->bloc_type }}" data-bid="{{ $bloc->id }}">
{{$bloc->id}}
@yield('bloc')
</section>
我对此有2个问题:
谢谢
答案 0 :(得分:2)
如果必须在视图中使用控制器,则仅意味着您没有那么好的架构。 Laravel的Blade可以轻松完成您想通过控制器解决的问题。
您可以将void draw()
{
printf("%p, %p\n", queue, compute.queue);
VulkanExampleBase::prepareFrame();
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
VulkanExampleBase::submitFrame();
// Submit compute commands
// Use a fence to ensure that compute command buffer has finished executin before using it again
vkWaitForFences(device, 1, &compute.fence, VK_TRUE, UINT64_MAX);
vkResetFences(device, 1, &compute.fence);
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
computeSubmitInfo.commandBufferCount = 1;
computeSubmitInfo.pCommandBuffers = &compute.commandBuffer;
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, compute.fence));
sleep(1000);
}
与参数一起使用,并摆脱@include
:
资源/视图/页面/edit.blade.php
@php
资源/视图/blocs/show.blade.php
@foreach ($page->blocs as $bloc)
@include('blocs.show', ['bloc' => $bloc])
@endforeach
资源/视图/blocs/show/text.blade.php
<section class="bloc bloc_{{ $bloc->bloc_type }}" data-bid="{{ $bloc->id }}">
{{$bloc->id}}
@include('blocs.show.' . $bloc->bloc_type, [
'bloc' => $bloc,
'data' => json_decode($bloc->data)
])
</section>