PHP code example of cornernote / yii2-linkall

1. Go to this page and download the library: Download cornernote/yii2-linkall 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/ */

    

cornernote / yii2-linkall example snippets


class Post extends ActiveRecord
{
    public function behaviors()
    {
        return [
            \cornernote\linkall\LinkAllBehavior::className(),
        ];
    }

    public function getTags()
    {
        return $this->hasMany(Tag::className(), ['id' => 'tag_id'])
            ->viaTable('post_to_tag', ['post_id' => 'id']);
            //->via('postToTag');
    }
}

class Tag extends ActiveRecord
{

}

class PostController extends Controller
{
    public function actionExample()
    {
        $post = Post::findOne(1);
        $tags = [Tag::findOne(2), Tag::findOne(3)];
        
        $extraColumns = []; // extra columns to be saved to the many to many table
        $unlink = true; // unlink tags not in the list
        $delete = true; // delete unlinked tags
        
        $post->linkAll('tags', $tags, $extraColumns, $unlink, $delete);
    }
}