sdailover/yii2-phpsessconnector
Composer 安装命令:
composer require sdailover/yii2-phpsessconnector
包简介
The SDaiLover PHP Session Connector extension for the Yii framework
README 文档
README
SDaiLover PHPSessionConnector for Yii 2
yii2-phpsessconnector
Runtime database helper to choose PHP Session or another database without change structure model of Yii framework 2.0.
For license information check the LICENSE-file.
Documentation is at docs/guide/README.md.
Report Bug · Request Feature · Provide Feedback · Ask Question
Love the project? Please consider donating or give ⭐ to help it improve!
Copyright © ID 2024 SDaiLover (www.sdailover.com)
All rights reserved.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist sdailover/yii2-phpsessconnector
or add
"sdailover/yii2-phpsessconnector": "~1.0.0"
to the require section of your composer.json.
App Configuration
To use this extension, simply add the following code in your application configuration:
return [ //.... 'components' => [ 'db' => [ 'class' => '\sdailover\yii\phpsessconnector\SDConnection', 'dsn' => 'phpsession:sdailover', // prefix name of session 'tablePrefix' => 'sd_' ], ], ];
Model Usage
To connect a database using ActiveRecord into a Model class:
namespace app\models; use sdailover\yii\phpsessconnector\SDActiveRecord; class ModelClass extends SDActiveRecord { //.... /* Create list attribute or name's field of database. */ public $attribute; /** * Default data imported into the php session, * this data only load to php session and not * import data to real database (mysql, sqlite, others). */ private static $data = [ [ 'attribute' => 'value', //.... ] ]; /** * Set the name of the database table or table session. */ public static function tableName() { return '{{tablename}}'; } /** * Load and import default data to php session. */ public static function loadTable() { parent::records(static::$data); } //.... }
Provider Usage
Data Providers are usually used to search in Models or display Models in the form of widgets such as GridView and other extensions. To implement it into the application created, we can configure it as follows:
namespace app\models; use app\models\ModelClass; use sdailover\yii\phpsessconnector\SDActiveProvider; class ModelSearchClass extends ModelClass { //.... public function search($params) { $query = ModelClass::find(); $dataProvider = new SDActiveProvider([ 'query' => $query ]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } // Add filter condition if ($this->attribute !== null && !empty($this->attribute)) $query->andFilterWhere(['attribute' => $this->attribute]); return $dataProvider; } //.... }
Controller Usage
To use the SDActiveRecord and SDDataProvider that have been created, we can implement them into the Controller that will be used as follows:
namespace app\controllers; use yii\web\Controller; use app\models\ModelClass; use app\models\ModelSearchClass; class SiteController extends Controller { //.... /** * Display model from SDActiveRecord. */ public function actionView() { $pkId = Yii::$app->request->isGet ? Yii::$app->request->get('attribute') : Yii::$app->request->post('attribute'); $model = ModelClass::findOne($pkId); return $this->render('view', ['model'=>$model]); } /** * Display many model from SDActiveRecord with Data Provider. */ public function actionSearch() { $searchModel = new ModelSearchClass(); $searchParams = Yii::$app->request->isGet ? Yii::$app->request->get() : Yii::$app->request->post(); $dataProvider = $searchModel->search($searchParams); return $this->render('search', ['dataProvider'=>$dataProvider]); } //.... }
Support the project
We open-source almost everything We can and try to reply to everyone needing help using these projects. Obviously, this takes time. You can use this service for free.
If you are using this project and are happy with it or just want to encourage us to continue creating stuff, there are a few ways you can do it:
- Giving proper credit on the GitHub Sponsors page.
- Starring and sharing the project ⭐
- You can make one-time donations via PayPal. I'll probably buy a coffee ☕ or tea 🍵 or cake 🍰
- It’s also possible to support mine financially by becoming a backer or sponsor through
However, we also provide software development services. You can also invite us to collaborate to help your business in developing the software you need. Please contact us at:
🙏 Thanks for your contribute and support! 😍 ❤️
Any Questions & Other Supports? see Support please.
Visit Website · Global Issues · Global Discussions · Global Wiki
Copyright © ID 2024 by SDaiLover (www.sdailover.com)
All rights reserved.
sdailover/yii2-phpsessconnector 适用场景与选型建议
sdailover/yii2-phpsessconnector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Connection」 「active-record」 「yii2」 「sdailover」 「phpsessconnector」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sdailover/yii2-phpsessconnector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sdailover/yii2-phpsessconnector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sdailover/yii2-phpsessconnector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Inspired by and put together the awesomeness of many yii extensions that aim to improve saving of related records. Comes with 100% test coverage and well structured and clean code so it can savely be used in enterprise production enviroment.
A custom URL rule class for Yii 2 which allows to create translated URL rules
Active record implementation
Small service to parse database connection string into parts
Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for HiblaPHP
MongoDB extension for the Yii framework
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-03-01