dowilcox/blade-view

该包已被废弃且不再维护。未建议替代包。

CakePHP3 的 Blade 模板引擎

安装: 29

依赖者: 0

建议者: 0

安全性: 0

星星: 15

关注者: 4

分支: 6

公开问题: 2

类型:cakephp-plugin

v0.2.1 2014-10-01 20:32 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:40:03 UTC


README

Laravel 的 Blade 模板引擎在 CakePHP 3 中。

安装

Composer

    [
        "require": {
            "dowilcox/blade-view": "0.2.*"
        }
    ]

在您的 bootstrap.php 中

Plugin::load('BladeView', ['bootstrap' => false]);

在您的控制器中

public $viewClass = '\Dowilcox\BladeView\View\BladeView';

现在将 src/Template 中的所有模板文件从 .ctp 改为 .blade.php

用法

查看 Laravel 的 Blade 文档:https://laravel.net.cn/docs/4.2/templates

CakePHP 视图函数和辅助函数的工作方式略有不同。

###变量之前

<?php echo h($variable); ?>

之后

{{{ $variable }}}

###视图函数:之前

<?php echo $this->fetch(); ?>

之后

@fetch()

###辅助函数(如果已在控制器中加载):之前

<?php echo $this->Html->css(); ?>

之后

@html->css()

更多示例

{{-- src/Template/Common/view.blade.php --}}
<h1>@fetch('title')</h1>
@fetch('content')

<div class="actions">
    <h3>Related actions</h3>
    <ul>
    @fetch('sidebar')
    </ul>
</div>
{{-- src/Template/Posts/view.blade.php --}}
@extend('/Common/view')

@assign('title', $post)

@start('sidebar')
<li>
    @html->link('edit', [
        'action' => 'edit',
        $post['Post']['id']
    ])
</li>
@end()

{{-- The remaining content will be available as the 'content' block --}}
{{-- In the parent view. --}}
{{{ $post['Post']['body'] }}}