How to display all session variables |
[eluser]fserrano[/eluser]
How can I quickly display all my session variables in the session array? I can't see the answer to this question in the User Guide Session Class page. This wouldn't work: Code: echo "<pre>"; This wouldn't work either: Code: echo "<pre>";
[eluser]edjon2000[/eluser]
Hi fserrano, all you need to do is modify your code slightly, instead of Code: echo "<pre>"; Code: echo "<pre>"; print_r is a command so doesn't need to be echoed. another thing you can try if you need to identify data types as well, is Code: echo "<pre>"; here is a link with further information http://php.net/manual/en/function.print-r.php Hope this helps you Jon
[eluser]Cristian Gilè[/eluser]
$this->session() is not valid! If you want to print the object content the right way is: Code: print_r($this->session); without parentheses. To extract a single element you could use the element function in the array helper: Code: $this->load->helper('array'); get_object_vars is needed to get the properties of the session object. Cristian Gilè
[eluser]edjon2000[/eluser]
Lol Cristian, I can't believe I missed that in my response, thanks for the correction, I have updated my post. Jon
[eluser]fserrano[/eluser]
Ah, thanks. This worked: Code: echo "<pre>";
[eluser]edjon2000[/eluser]
[quote author="fserrano" date="1295044272"]Ah, thanks. This worked: Code: echo "<pre>"; Hmm even with the echo on the second line ? Jon
[eluser]Cristian Gilè[/eluser]
The return value of print_r is TRUE, so you can echo TRUE but it is useless. Cristian Gilè
[eluser]edjon2000[/eluser]
Yeah thats what I thought too Cristian I must admit I have used print_r and var_dump since I started programming in PHP, and it is helping me out with my current web project which I decided to build using CodeIgniter quite a learning curve for me at the moment, so you will no doubt see some fairly newbie qustions around this forum from me. actually, that raises a question, I have a few useful functions that I use routinely for debugging web projects to such an extent that I put together a funcs.php file which I just included in whatever I was working on whilst developing a site, In CI however, you can't include files in the same way, could useful code snippets like the print_r and the var_dump statements be added in such a way as to make them globally available within a CI project(normally in a traditional XHTML/PHP/MySQL site I would include the funcs.php file and just call them individually as functions) so I would have a function like Code: function show_array($array) Code: show_array($_POST}; What are your thoughts on this Jon
[eluser]edjon2000[/eluser]
Ah ok thanks Cristian, I hope I have not hi-jacked this thread, it is just that my my question was loosely related to fserrano's original post. Jon |
Welcome Guest, Not a member yet? Register Sign In |