开发者

Code Igniter - print $Controller->session without knowing the key?

Instead of doing the following:

print $this->session开发者_C百科->userdata('username');
print $this->session->userdata('email');
print $this->session->userdata('phone');
print $this->session->userdata('fax');
//etc...

Is there a way to do something like

foreach($this->session as $key=>$val) print $key.'-'.$val;

Or is it possible to do something like

print_r($this->session);

The reason I'm asking is because I don't know what the SESSION keys are and I also want to be able to loop through CI Session values.


$this->session is an object of course,and you can dump it using print_r or var_dump

but i recommend using this for fetching all of your session data except for flash data:

$sessionArray = $this->session->all_userdata();


You can do

print_r($this->session);

It will return an array of all your sessions.


For me it worked by casting $this->session as and array then dumping it.

        $this->load->library('session'); #load session
        foreach ((array)$this->session as $sess_arr_k => $sess_arr_v)
        {
          "<li>". $sess_arr_k .":<br />". var_dump($arrSessElement) ."</li>";
        }

Worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜