how to i print session on view page in zend framework -
i new zend framework, , going add session in small application dont know how print session variable header.phtml page.
userstable.php
public function fetchbywhere($where) { $rowset = $this->tablegateway->select($where); $row = $rowset->current(); if (!$row) { return; } return $row; }
indexcontroller.php
<?php namespace application\controller; use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel; use application\model\users; // <-- add import use zend\session\container; // need when using sessions class indexcontroller extends abstractactioncontroller { protected $userstable; public function getuserstable() { if (!$this->userstable) { $sm = $this->getservicelocator(); $this->userstable = $sm->get('application\model\userstable'); } return $this->userstable; } public function indexaction() { $request = $this->getrequest(); if ($request->ispost()) { $user = $request->getpost('txtuser'); $pass = $request->getpost('txtpassword'); $wher = array('username' => $user, 'password' => $pass); $resultset = $this->getuserstable()->fetchbywhere($wher); //var_dump($resultset); if($resultset) { $user_session = new container('user'); $user_session->ses_user = $resultset->username; return new viewmodel(array( 'msg' => 'valid user', 'sesuser' => $user_session->ses_user, )); } else { return new viewmodel(array( 'msg' => 'not valid user', )); } } else { return new viewmodel(); } } }
now dont know how print session on header.phtml page.
you need add session container in header file well.
add following line in header file.
<?php use zend\session\container; // need when using sessions $user_session = new container('user'); if(isset($user_session->ses_user)) echo "user:".$user_session->ses_user; ?>
Comments
Post a Comment