php - CodeIgniter How to access session variables in twig templates -
somebody can me please. i'm new in codeigniter , twig. have declared in controller following:
$datasession = array( 'nick' => $sess_nick, 'login_ok' => true ); $this->session->set_userdata($datasession); redirect('app'); //app controller render template view.
then, question is: how can variables twig template? tried using:
{{ session.userdata.nick }}
but shows empty string.
thanks advance.
to add session variable on twig template, have add following line in twig library or controller.
$datasession = array( 'nick' => $sess_nick, 'login_ok' => true ); $this->session->set_userdata($datasession); $this->_twig->addglobal("session", $this->ci->session);
then on twig template, can print session this
{{ session.userdata.nick }}
since in codeigniter, session stored user in userdata array. otherwise, can call session variable , name
{{ session.nick }}
src: http://llanalewis.blogspot.co.uk/2013/08/codeigniter-add-session-in-twig.html
Comments
Post a Comment