gutocf/page-title

CakePHP 4 的页面标题组件

安装次数: 2,724

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:cakephp-plugin

1.2.0 2024-02-01 21:25 UTC

This package is auto-updated.

Last update: 2024-08-31 00:31:33 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads License PHPStan Packagist Version

需求

  • PHP 8.1+
  • CakePHP 5.0+

注意:要使用 PHP 8.0 和 CakePHP 4.3+,请查看版本 1.1.1

安装

使用 composer 安装插件

composer require gutocf/page-title

插件加载

bin/cake plugin load PageTitle

组件加载

App\Controller\AppController 中加载组件

$this->loadComponent('Gutocf/PageTitle.PageTitle', [
   'default' => 'MyApp Name', //Default page title - optional, default = null
   'var' => 'var_name_for_views', //Var name to set at view - optional, default = title
   'separator' => ' :: ', //Titles separator - optional, default = ' / '
   'reverseOrder' => true, //Display titles in reverse order of inclusion - optional, default = true
]);

您需要在控制器或应用程序的 AppController 中加载组件(推荐)。

用法

要添加页面标题,只需使用一个或多个参数调用 PageTitle::add 方法。

$this->PageTitle->add('Articles', 'Add');

Controller.beforeRender 事件中,组件将设置一个名为 $config['var'] 的变量,用于视图和模板。在此示例中为 添加 :: 文章 :: MyApp 名称(如果 reverseOrder 选项为 false,则为 MyApp 名称 :: 文章 :: 添加)。您可以通过在模板文件 src/templates/default.php 中包含此代码来设置页面标题。

<head>
   <title><?= $this->get('var_name_for_views') ?></title>
</head>