如何在 Zend To Native 中传递会话变量 PHP

How to Pass A Session Variable in Zend To Native PHP

我想将变量从 Zend 框架传递到同一服务器中的本机 php 文件。

我试过的

$auth = Zend_Auth::getInstance();
     if($auth->hasIdentity())
        {

          $user = $auth->getIdentity();
          $username33 = $this->escape(ucfirst($user->username));
          $_SESSION['thisisnotit']=$username33;
       }

然后我在我的 php 页面上尝试了这个

echo $notit = $_SESSION['thisisnotit'];

显然这给了我一个错误。我了解 Zend 中会话的语法是

$myNamespace = new Zend_Session_Namespace('myNamespace');

但是我如何让它工作以便我可以访问我的 php 文件中的变量

您的目标是获得授权服务。因此,对于该服务或您想要的任何服务,首先您需要加载 ZF2 应用程序以获取您的身份验证服务。 按照 working/tested 代码实现这个 -

require 'init_autoloader.php';
// Run the application!
$app=Zend\Mvc\Application::init(require 'config/application.config.php');
$authService=$app->getServiceManager()->get('AuthenticationService');
echo 'Session Data: <pre>'.print_r($authService->getIdentity(), true);

欢迎更高效的方式。