PHP code example of locustv2 / yii2-linkable-behavior
1. Go to this page and download the library: Download locustv2/yii2-linkable-behavior 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/ */
locustv2 / yii2-linkable-behavior example snippets
namespace app\models;
use yii\db\ActiveRecord;
use locustv2\behaviors\LinkableBehavior;
class User extends ActiveRecord
{
//...
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
[
'class' => LinkableBehavior::className(),
'route' => '/user',
'defaultAction' => 'view',
'hotlinkTextAttr' => 'username',
'defaultParams' => function ($record) {
return [
'id' => $record->id,
];
},
]
]);
}
}
namespace app\models;
use yii\db\ActiveRecord;
use locustv2\behaviors\LinkableBehavior;
class Photo extends ActiveRecord
{
//...
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
[
'class' => LinkableBehavior::className(),
'route' => '/photo',
'defaultAction' => 'view',
'linkableParams' => function ($record) {
return [
'photoid' => $record->id,
];
},
'useAbsoluteUrl' => true,
'defaultParams' => function ($record) {
return [
'id' => $record->id,
'slug' => $record->slug
];
},
]
]);
}
}