承接 nixphp/session 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nixphp/session

最新稳定版本:v0.1.0

Composer 安装命令:

composer require nixphp/session

包简介

NixPHP Session Plugin for storing data across requests.

README 文档

README

Logo

NixPHP Session Plugin

← Back to NixPHP

nixphp/session

Simple session management for NixPHP, with flash message support built-in.

This plugin adds a lightweight, dependency-free session handler to your NixPHP app. It starts the session automatically and provides helpers for storing data across requests — including flash messages.

🧩 Part of the official NixPHP plugin collection. Install it when you need session persistence — and nothing else.

📦 Features

  • Starts PHP sessions automatically
  • Store/retrieve session data easily
  • Flash message system for one-time notices
  • No configuration needed
  • PSR-11 container integration (session())

📥 Installation

composer require nixphp/session

Once installed, the plugin is autoloaded and ready to use.

🚀 Usage

📌 Accessing the session

Use the global session() helper to access the session storage:

session()->set('user_id', 42);

$userId = session()->get('user_id');

To remove a key:

session()->forget('user_id');

✨ Flash messages

Use flash messages to store data for the next request only (e.g. after a redirect):

session()->flash('success', 'Profile updated.');

In the next request, access it using:

<?php if ($message = session()->getFlash('success')): ?>
    <p class="success"><?= $message ?></p>
<?php endif; ?>

The message is then automatically removed after it has been read.

🔍 Internals

  • Automatically starts session_start() if it hasn't run yet.
  • Flash data is stored in a dedicated key and removed after access.
  • Registers the session() helper and binds it in the service container.

🛠 Optional Usage in Controllers

You can also access the session directly from the container:

$session = app()->container()->get(Session::class);

But using the session() helper is the recommended way.

✅ Requirements

  • nixphp/framework >= 0.1.0

📄 License

MIT License.

统计信息

  • 总下载量: 47
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03