我如何将 yii 框架中的会话用于我的 3rd 方应用程序

编程入门 行业动态 更新时间:2024-10-17 02:47:01
本文介绍了我如何将 yii 框架中的会话用于我的 3rd 方应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我使用 Yii 框架,并且在该框架中我使用了 mibew Messenger(或 chat)的第 3 方应用程序.

我需要的是将 $_session 变量(用户名和密码)从 yii 框架传递给 Mibew messenger,我需要这个,因为我想在什么时候自动登录我登录到我的 yii 应用程序.

Mibew messenger 文件夹位于应用程序的 app 文件夹中.

那么如何在 yii 框架 之外使用相同的会话?

感谢您的帮助.

解决方案

我认为您可以执行以下操作:

1) 在您需要访问 SESSION 的第 3 方应用程序文件中:

<块引用>

require('/path/to/framework/YiiBase.php');

2) 如果您有特定的会话配置,那么您需要配置:

<块引用>

$config = require('/path/to/protected/config/main.php');$session = YiiBase::createComponent($config['components']['session']);

3) 对于标准会话(而不是第 2 步),您应该尝试:

<块引用>

$session = new CHttpSession();

您可以像在框架中一样使用会话:$session[$var_name]$session->get/set($var_name).

我不检查它的解决方案.如果有错误 - 写在评论中.

更新

只需要做:

<块引用>

require('/path/to/framework/YiiBase.php');$config = require('/path/to/configs_directory/main.php');Yii::createWebApplication($config);

你可以通过 Yii::app()

使用所有框架功能

I use Yii framework and in the framework i use 3rd party application which is mibew Messenger (or chat ).

What I need is to pass $_session variable (username and password) from yii framework to Mibew messenger, I need this because I want to be log in automatically when I log in into my yii application.

Mibew messenger folder is in the app folder of the application.

So how can I use the same session outside of yii framework ?

Thanks for the help.

解决方案

I think you may do following:

1) In file of 3rd party application where you need to get an access to SESSION:

require('/path/to/framework/YiiBase.php');

2) If you have specific configs for sessions, than you need you configs:

$config = require('/path/to/protected/config/main.php');
$session = YiiBase::createComponent($config['components']['session']);

3) For standard sessions (instead step #2) you should try:

$session = new CHttpSession();

Than you can work with sessions as in framework: $session[$var_name] or $session->get/set($var_name).

I don't check it solution. If there will be an error - write it on comments.

UPDATED

Just need to do:

require('/path/to/framework/YiiBase.php');
$config = require('/path/to/configs_directory/main.php');
Yii::createWebApplication($config);

Than you can use all framework features by Yii::app()

这篇关于我如何将 yii 框架中的会话用于我的 3rd 方应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:55:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   应用程序   框架   yii

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!