CodeIgniter Forums
Reading Session Var in Heper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Reading Session Var in Heper (/showthread.php?tid=15818)



Reading Session Var in Heper - El Forum - 02-16-2009

[eluser]nk94555[/eluser]
Hi,

I am defining a session var in my controller and using a helper file in the view. I am not able to read the session var defined in controller using $this->session->userdata('item'); It errors that helper is not a class. Is there a way to do this instead of passing var to each helper function call from views.

Thanks,
Neeraj


Reading Session Var in Heper - El Forum - 02-16-2009

[eluser]pistolPete[/eluser]
What helper are you using?


Reading Session Var in Heper - El Forum - 02-16-2009

[eluser]TheFuzzy0ne[/eluser]
Can you give us an example of your controller (including top line and constructor), and your view file?


Reading Session Var in Heper - El Forum - 02-16-2009

[eluser]nk94555[/eluser]
In controller:
$this->session->set_flashdata('flow', 'web');
$this->load->view('quote_summary',$data);

In view:
$this->load->helper('my_app_ui');

I created a helper "my_app_ui".

Calling the following function from view:
echo printSumRow($firm_data,'email','Email');

function printSumRow($pData,$pField,$pLabel,$pLongText=FALSE)
{
$flow = $this->session->flashdata('flow');
.
.
}

Inside the printSumRow function in helper I don't have access to $this->session. I can read this in view. I don't want to pass this in each and every function call to "printSumRow", I thought session might do.

Thanks


Reading Session Var in Heper - El Forum - 02-16-2009

[eluser]pistolPete[/eluser]
Use something like that:
Code:
function printSumRow($pData,$pField,$pLabel,$pLongText=FALSE)
{
   $CI =& get_instance();
   $flow = $CI->session->flashdata('flow');

(...)
}