mattyg/meta

一个易于将元标签添加到视图中的包。

2.1.6 2014-04-25 06:14 UTC

This package is auto-updated.

Last update: 2024-09-07 07:19:14 UTC


README

#Meta

一个易于将元标签添加到视图中的包。这是Ryan Nielson原始包的分支,不包含任何特定框架的代码。

此包可以在任何PHP应用程序中运行。

安装

在终端中运行以下Composer命令,或将"mattyg/meta": "2.1.*"添加到您的composer.json文件中

composer require mattyg/meta

然后从终端更新Composer

composer update

这样就完成了!

用法

要设置元标签值,您将使用Meta实例上的set(array())方法。只需传递这个Meta对象来持久化设置的值。

$meta = new \RyanNielson\Meta\Meta;

// Example #1 - Basic setting of values
$meta->set(array("title" => "Page Title", "description" => "Page Description", "keywords" => array("great", "site")));

// Example #2 - Setting nested values. This will render tags with names like og:title and og:description
$meta->set(array("title" => "Page Title", "og" => array("title" => "OG Title", "description" => "OG Description")));

要使用设置的值显示您的元标签,您将使用Meta对象上的display(array())函数。

$meta->display();

// Displaying Example #1 from above
<meta name="title" content="Page Title"/>
<meta name="description" content="Page Description"/>
<meta name="keywords" content="great, site"/>

// Displaying Example #2 from above
<meta name="title" content="Page Title"/>
<meta name="og:title" content="OG Title"/>
<meta name="og:description" content="OG Description"/>

显示函数还接受一个默认值数组。如果没有使用set()设置值,则显示元标签时将使用这些默认值。