Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yii2mod/yii2-link-preview
LinkPreview widget render page preview
https://github.com/yii2mod/yii2-link-preview
yii2 yii2-extension yii2-link-preview yii2-page-preview
Last synced: about 12 hours ago
JSON representation
LinkPreview widget render page preview
- Host: GitHub
- URL: https://github.com/yii2mod/yii2-link-preview
- Owner: yii2mod
- License: mit
- Created: 2015-07-02T09:58:23.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-03T08:13:30.000Z (over 6 years ago)
- Last Synced: 2024-09-18T22:33:08.765Z (9 days ago)
- Topics: yii2, yii2-extension, yii2-link-preview, yii2-page-preview
- Language: PHP
- Size: 35.2 KB
- Stars: 28
- Watchers: 10
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Yii2 Link Preview Widget
===========LinkPreview widget automatically retrieves some information from the content of the link.
[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-link-preview/v/stable)](https://packagist.org/packages/yii2mod/yii2-link-preview) [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-link-preview/downloads)](https://packagist.org/packages/yii2mod/yii2-link-preview) [![License](https://poser.pugx.org/yii2mod/yii2-link-preview/license)](https://packagist.org/packages/yii2mod/yii2-link-preview)
[![Build Status](https://travis-ci.org/yii2mod/yii2-link-preview.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-link-preview)Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
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
php yii migrate/up --migrationPath=@vendor/yii2mod/yii2-link-preview/migrations
```2) Define preview action in your controller:
```php
public function actions()
{
return [
'link-preview' => LinkPreviewAction::className()
];
}
```
3) Add widget to your page as follows:
```php
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
Preview
'#preview',
'clientOptions' => [
'previewActionUrl' => \yii\helpers\Url::to(['link-preview'])
],
]) ?>
= \yii\helpers\Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
```
2) Add the following code to your action for the saving page info:
```php
$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](http://res.cloudinary.com/zfort/image/upload/v1436190465/Preview.png "GitHub Preview Example")#### Video Link Preview Example
-----
![Alt text](http://res.cloudinary.com/zfort/image/upload/v1463675454/Youtube%20link%20preview.png "Video Link Preview Example")