Reputation: 51
I want to pass a variable from Zend frame work to a native php file in the same server.
what i tried
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$username33 = $this->escape(ucfirst($user->username));
$_SESSION['thisisnotit']=$username33;
}
then i tried this in my php page
echo $notit = $_SESSION['thisisnotit'];
Obviously this gave me an error. I understand the syntax of sessions in Zend is
$myNamespace = new Zend_Session_Namespace('myNamespace');
but how do i get this to work so that i can access the varible in my php file
Upvotes: 1
Views: 95
Reputation: 727
Your goal is to get auth service. So, for that or for any service you want, first you need to load ZF2 application to get your auth service. Following working/tested code to achieve this -
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);
More efficient way is welcome.
Upvotes: 1