PHP code example of thyseus / yii2-favorites

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

    

thyseus / yii2-favorites example snippets


'modules' => [
    'favorites' => [
        'class' => 'thyseus\favorites\Module',
    ],
],

use thyseus\favorites\models\Favorite;

$model = CurrentModel::findOne(57);
echo $this->render('@vendor/thyseus/yii2-favorites/views/favorites/_button', [
    'model' => CurrentModel::className(),
    'target' => $model->slug
]);

'aliases' => [
    '@favorites' => '@app/vendor/thyseus/yii2-favorites'
],


echo $this->render('@favorites/views/favorites/_button', [

public function identifierAttribute()
{
    return 'slug';
}

use thyseus\favorites\models\Favorite;

$model = CurrentModel::findOne(57);
echo $this->render('@vendor/thyseus/yii2-favorites/views/favorites/_button', [
    'model' => CurrentModel::className(),
    'target' => $model->id,
    'icon' => '<i class="fa fa-users" aria-hidden="true"></i>', // optional
    'url' => Url::to(['fancy-url', 'id' => 1337]) ,
]);

use thyseus\favorites\models\Favorite;

$model = CurrentModel::findOne(57);

echo $this->render('@vendor/thyseus/yii2-favorites/views/favorites/_button', [
    'model' => CurrentModel::className(),
    'target' => $model->id,
    'target_attribute' => 'i-am-referenced-by-this-column',
]);

public function getName()
{
    return $this->firstname . ' ' . $this->lastname;
}

echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'encodeLabels' => false,
    'items' => [
        ['label' => '<span class="glyphicon glyphicon-bookmark"></span>', 'options' => ['class' => 'favorites-menu clickable', 'style' => 'cursor: pointer;'], 'url' => false, 'visible' => !$user->isGuest, 'items' => ['' => '']],
      ]
    ]);