title: how to get session values in layout in Zend framework 1?
body: <p>I want to access session values from layout.xml.</p>
  
  <p>The code I did is</p>
  
  <p>Layout.xml</p>
  
  <pre><code>&lt;h2&gt;&lt;?php  $myprofile=new Zend_Session('user_session');
    print $myprofile-&gt;username; ?&gt; &lt;/h2&gt;
  </code></pre>
  
  <p>Index Controller/index action</p>
  
  <pre><code>  $userid = $this-&gt;_user-&gt;getUserId($username,$password);
    $session = new Zend_Session_Namespace('user_session');
    $session-&gt;username = $username;
    $session-&gt;password = $password;
    $session-&gt;uid = $userid;
    $this-&gt;_redirect('home');
  </code></pre>
  
  <p>Home Controller/index action</p>
  
  <pre><code>$this-&gt;session = new Zend_Session_Namespace('user_session');
  $this-&gt;view-&gt;uname = $this-&gt;session-&gt;username;
  </code></pre>
  
  <p>Home/index.phtml</p>
  
  <pre><code>&lt;?php echo "The User Name is ".$this-&gt;uname?&gt;
  </code></pre>
  
  <p>But it shows an error</p>
  
  <pre><code>Fatal error: Call to protected Zend_Session::__construct() from context 'Zend_View' in/var/www/shoppingcart/application/layouts/scripts/layout.phtml on line 19
  </code></pre>
  
  <p>I am able to get the session values in Home/index.html.</p>
  
  <p>Expecting positive help.</p>