dowilcox / blade-view
该包已被废弃且不再维护。未建议替代包。
CakePHP3 的 Blade 模板引擎
v0.2.1
2014-10-01 20:32 UTC
Requires
- cakephp/cakephp: 3.0.*-dev
- cakephp/plugin-installer: dev-master
- illuminate/view: 4.2.*
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'] }}}