thyseus/yii2-favorites
Composer 安装命令:
composer require thyseus/yii2-favorites
包简介
General favorite management for Yii2
关键字:
README 文档
README
A General Favorites Manager for the Yii 2 framework. Every ActiveRecord Model can be bookmarked and accessed later by an authorized user. Contains only one table 'favorites' where everything is stored.
Installation
$ composer require thyseus/yii2-favorites
$ php yii migrate/up --migrationPath=@vendor/thyseus/yii2-favorites/migrations
Configuration
Add following lines to your main configuration file:
'modules' => [
'favorites' => [
'class' => 'thyseus\favorites\Module',
],
],
Integration in your application:
use
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
]);
to display a "Set as Favorite" / "Remove Favorite" toggle Button in the view files of the models you want to make your users to be able to add favorites to.
Note that you can shorten the call if you set an alias like this in your application configuration:
'aliases' => [
'@favorites' => '@app/vendor/thyseus/yii2-favorites'
],
And call the view like:
echo $this->render('@favorites/views/favorites/_button', [
If the model is not identified by the column 'id' by default, for example if you are using slugs, you can define the indentifierAttribute inside the model like this:
public function identifierAttribute()
{
return 'slug';
}
If the automatic URL creation if yii2-favorites fails, you can append the URL manually:
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 the fourth parameter to set an custom target_attribute:
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',
]);
If you want to use composite label identifiers, you can do it like this:
public function getName()
{
return $this->firstname . ' ' . $this->lastname;
}
You can use this code example to make an dynamic menu containing your favorites in the NavBar:
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' => ['' => '']],
]
]);
$this->registerJs("
$('.favorites-menu').click(function() {
$.getJSON('".Url::to(['//favorites/favorites/json'])."', function (data) {
dd = $('.favorites-menu').find('.dropdown-menu');
dd.html('');
dd.append('<li><a href=\"".Url::to(['//favorites/favorites/index'])."\">Manage favorites</a></li>');
data.forEach(function(elem) {
dd.append('<li>' + (elem.icon ? elem.icon : '') + ' <a href=\"' + elem.url + '\">' + elem.title.substring(0, 60) + '</a></li>');
});
});
});
");
.favorites-menu li a { display: inline; padding: 0; }
.favorites-menu .dropdown-menu { padding: 10px; }
Routes
You can use the following routes to access the favorites module:
- list all favorites of the current logged in user: https://your-domain/favorites/favorites/index
- view: https://your-domain/favorites/favorites/view?id=
- update: 'favorites/update/' => 'favorites/favorites/update',
- delete: 'favorites/delete/' => 'favorites/favorites/delete',
- view: 'favorites/' => 'favorites/favorites/view',
License
Yii2-favorites is released under the GPLv3 License.
thyseus/yii2-favorites 适用场景与选型建议
thyseus/yii2-favorites 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.19k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2」 「yii2-favorites」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thyseus/yii2-favorites 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thyseus/yii2-favorites 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thyseus/yii2-favorites 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Redirect all not authenticated web user to login page.
React javascript library for Yii2
Yii 2 RBAC Module
Circular navigation widget for Yii 2 Framework.
统计信息
- 总下载量: 1.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPLv3
- 更新时间: 2016-11-17