adrianoluis/cake-php-yourls-plugin

此包已被弃用且不再维护。未建议替代包。

安装: 10

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 0

分支: 0

开放问题: 0

类型:cakephp-plugin

dev-master 2016-01-29 18:37 UTC

This package is not auto-updated.

Last update: 2020-01-22 20:28:53 UTC


README

安装和设置

首先将此仓库添加为您的 CakePHP 项目中的 git 子模块

git submodule add https://github.com/adrianoluis/CakePHP-YOURLS-Plugin.git APP/Plugin/Yourls
git submodule update --init

安装完成后,您需要创建一个文件 /APP/Config/yourls.php。您可以在 /Yourls/Config/yourls.php.example 中找到所需的示例和布局。

//app/Config/yourls.php
$config = array(
	'Yourls' => array(
		'url' => 'YOURLS_URL',
		'username' => 'YOURLS_USERNAME',
		'password' => 'YOURLS_PASSWORD',
	)
);

用法

您可以从控制器中的任何操作调用组件,或使用以下代码在您的 /APP/Controller/AppController.php 中自动化 URL 缩短:

public function beforeRender() {
	$this->shortIt = true;
	$this->pageTitle = 'your url title goes here'
}

PS:对于缩短方法,需要提供标题,否则将无限循环尝试使用 YOURLS 内部库解析 URL 的标题。

然后从您的视图中,使用以下方法访问缩短的 URL:

<?php echo $shorturl['url']; ?>

要获取所有链接的统计数据,您需要选择 json 或 xml。这种新的设置改变了 shorturl 方法的返回值。

public $components = array(
	'Yourls.Yourls' => array(
		'format' => 'xml'
	)
);