我想将变量从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应用程序以获取身份验证服务。按照工作/经过测试的代码来实现这一目标-
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);
欢迎使用更有效的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句