drnixx/yii2-schema-org

Schema.org的yii2表示和json-ld生成助手,用于Yii框架

安装: 57

依赖关系: 0

建议者: 0

安全性: 0

星标: 1

观察者: 3

分支: 4

类型:yii2-extension

1.5.3 2018-11-09 11:54 UTC

This package is not auto-updated.

Last update: 2024-09-24 17:42:00 UTC


README

Schema.org的yii2表示和json-ld生成助手

资源

安装

安装此扩展的首选方式是通过composer

运行以下命令之一:

$ php composer.phar require --prefer-dist drnixx/yii2-schema-org

或者

"drnixx/yii2-schema-org": "*"

将其添加到您的composer.json文件的require部分

使用方法

设置模块

在您的Yii配置文件的模块部分配置名为schema的模块。对于控制台和Web应用程序配置文件,都这样做。

'modules' => [
	'schema' => [
		'class' => 'drnixx\schemaorg\Module',
		//'source' => 'http://schema.org/docs/full.html',
		//'autoCreate' => false,
		//'autoRender' => false
	]
]

同时将模块schema添加到配置文件的引导部分

'bootstrap' => ['log', 'schema']

配置

source参数定义了schema.org属性文档的根URL。它用于在控制台应用程序中自动创建模型。

自动创建

自动创建面包屑json+ld数据。

自动渲染

自动在body部分的末尾渲染json+ld数据。

如果您不使用此参数,请确保在布局文件中调用JsonLDHelper::render()。示例

<?php
/* @var $this \yii\web\View */
/* @var $content string */
use app\widgets\Alert;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use drnixx\schemaorg\helpers\JsonLDHelper;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php JsonLDHelper::render(); ?>
    <?php $this->head() ?>
</head>

模型生成

$ php yii schema/schema-org

示例用法

例如,要将人员添加到json+ld中,可以执行以下操作

use drnixx\schemaorg\models\Person;
use drnixx\schemaorg\helpers\JsonLDHelper;

$child = new Person();
$child->name = 'George W. Bush';
$child->disambiguatingDescription = '43rd President of the United States';
$person = new Person();
$person->name = 'George Bush';
$person->disambiguatingDescription = '41st President of the United States';
$person->children = [$child];

JsonLDHelper::add($person);

许可证

yii2-schema-org在MIT许可证下发布。有关详细信息,请参阅附带LICENSE