renus / last-tweet
Symfony 2 bundle,用于快速在您的网站上添加最新推文
v1.0.2
2015-05-15 10:54 UTC
Requires
- abraham/twitteroauth: ^0.5.3
This package is not auto-updated.
Last update: 2024-09-14 18:25:53 UTC
README
Symfony 2 bundle,用于快速在您的网站上添加最新推文,您可以选择和更改屏幕名称,覆盖模板并使用自己的模板,此bundle需要依赖abraham/twitteroauth bundle
安装
先决条件
当您为symfony安装RenusLastTweetBundle时,此依赖将被添加
https://github.com/abraham/twitteroauth
安装步骤
1. 将此bundle添加到您的项目中composer.json
{
"require": {
"renus/last-tweet": "1.*",
}
}
2. 或者使用composer安装
composer.phar require renus/last-tweet dev-master
3. 注册bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new \Renus\LastTweetBundle\RenusLastTweetBundle(), ); // ... }
#配置
##应用Twitter
首先,您必须在https://apps.twitter.com/上创建一个Twitter应用,并创建一个令牌(读取权限)
##参数
1. 配置文件
您必须在app/config/config.yml中添加您的Twitter API参数,必须添加的参数如下
# app/config/config.yml renus_last_tweet: twitter: consumer_key: "your_application_key" consumer_secret: "your_application_secret_key" token: "your_application_token" token_secret: "your_application_token_secret"
2. 路由文件
# app/config/routing.yml renus_last_tweet: resource: "@RenusLastTweetBundle/Resources/config/routing.yml" prefix: /
#使用方法
##TWIG使用
只需将此渲染命令添加到您的TWIG模板中(在此示例中,我们显示来自@renus_net账户的最后3条推文)
{% render path('renus_last_tweet', {screen: 'renus_net', number: 3}) %}
##控制器使用
如果您想在控制器中使用它,可以使用以下代码获取一个实体数组
<?php // src/controller/someController.php public function someAction() { $tweets = $this->get('renus.twitter')->getLastTweets($screen, $number); // ... //if you want retweets and mention $tweets = $this->get('renus.twitter')->getLastTweets($screen, $number, false, true); }
#覆盖模板
如果您想自定义渲染(在TWIG模板中使用),您可以在app/config/config.yml中指定覆盖模板的路径
##配置
# app/config/config.yml renus_last_tweet: twitter: consumer_key: "your_application_key" consumer_secret: "your_application_secret_key" token: "your_application_token" token_secret: "your_application_token_secret" template: path: "path/of/custom/template/tweet.html.twig"
##模板
您可以像这样使用“tweets”实体数组
{% for tweet in tweets %}
<dl>
<dt>{{ tweet.getDate() }}</dt>
<dd>{{ tweet.getFormatText() | raw }}</dd>
</dl>
{% endfor %}
要查看所有'tweet'参数,请打开Entity/Tweet.php