yii2mod/yii2-link-preview 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yii2mod/yii2-link-preview

最新稳定版本:1.3

Composer 安装命令:

composer require yii2mod/yii2-link-preview

包简介

LinkPreview widget renders page preview

README 文档

README

LinkPreview widget automatically retrieves some information from the content of the link.

Latest Stable Version Total Downloads License Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii2mod/yii2-link-preview "*"

or add

"yii2mod/yii2-link-preview": "*"

to the require section of your composer.json file.

Usage

  1. Execute init migration:
php yii migrate/up --migrationPath=@vendor/yii2mod/yii2-link-preview/migrations
  1. Define preview action in your controller:
public function actions()
{
    return [
        'link-preview' => LinkPreviewAction::className()
    ];
}
  1. Add widget to your page as follows:
echo LinkPreview::widget([
    'selector' => '#your-input-id or .someclass',
    'clientOptions' => [
        'previewActionUrl' => \yii\helpers\Url::to(['link-preview'])
    ],
])

Example of usage with the ActiveForm and saving the page info

  1. Create the basic form in the view:
<?php $form = \yii\widgets\ActiveForm::begin() ?>
    <div class="form-group">
        <label for="preview">Preview</label>
        <input name="preview" class="form-control" id="preview" placeholder="Preview">
    </div>
    <?php echo \yii2mod\linkpreview\LinkPreview::widget([
        'selector' => '#preview',
        'clientOptions' => [
            'previewActionUrl' => \yii\helpers\Url::to(['link-preview'])
        ],
    ]) ?>
    <div class="form-group">
        <?= \yii\helpers\Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
    </div>
<?php \yii\widgets\ActiveForm::end() ?>
  1. Add the following code to your action for the saving page info:
$model = new LinkPreviewModel();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
    $model->save();
}

// or the short version 

$linkPreviewId = LinkPreviewModel::saveAndGetId(Yii::$app->request->post());

GitHub Preview Example

Alt text

Video Link Preview Example

Alt text

统计信息

  • 总下载量: 1.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 8
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-02