PHP code example of yii2mod / yii2-link-preview

1. Go to this page and download the library: Download yii2mod/yii2-link-preview library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yii2mod / yii2-link-preview example snippets


php yii migrate/up --migrationPath=@vendor/yii2mod/yii2-link-preview/migrations

public function actions()
{
    return [
        'link-preview' => LinkPreviewAction::className()
    ];
}

echo LinkPreview::widget([
    'selector' => '#your-input-id or .someclass',
    'clientOptions' => [
        'previewActionUrl' => \yii\helpers\Url::to(['link-preview'])
    ],
])

 $form = \yii\widgets\ActiveForm::begin() 

$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());


php composer.phar