How to avoid errors in view when I am using variable for the php session |
[eluser]shinokada[/eluser]
I am using php session. In a view when I use the following code, I get the error notice. It is not displayed, but when I see the source code, it's there. In a view: Code: $totalprice = $_SESSION['totalprice']; Error Code: <h4>A PHP Error was encountered</h4> If I put it a controller, I get another error. In a controller: Code: $data['totalprice']= $_SESSION['totalprice']; Error Code: <h4>A PHP Error was encountered</h4> The second case is worse since the doc type and other header section is gone. Can anyone tell me how to do it? (Please don't ask me or why I am not using ci session class.)
[eluser]Sbioko[/eluser]
You see this error, because there are no totalprice item in your session. Use this to see your session's items: Code: print_r($_SESSION);
[eluser]Yorick Peterse[/eluser]
As said by demedes, you get that error since the item doesn't exist. Use the following code to check whether the item exists or not. You should also note that plain PHP sessions don't work with CodeIgniter by default. Code: <?php
[eluser]shinokada[/eluser]
It is there. If I do Code: print_r ($_SESSION['totalprice']); It print out 418. And if I do Code: print_r ($_SESSION); It will print out all other information.
[eluser]Sbioko[/eluser]
Code: print_r($_SESSION); Quote:(Please don’t ask me or why I am not using ci session class.)Sorry but, why you don't use the native CI session library? :-)
[eluser]aidehua[/eluser]
Can you show us the full print-out result when you run Code: print_r ($_SESSION); (Preferably copied from the source so that it's nicely laid out with line-breaks...)
[eluser]shinokada[/eluser]
The reason I am not using CI session. 1. I am using code from Codeigniter Professional which uses PHP session. 2. Please read this thread http://ellislab.com/forums/viewthread/130577/
[eluser]shinokada[/eluser]
@aidehua It does not show in the source. But it is on the page. print_r ($_SESSION); outputs the followings. Code: Array (
[eluser]aidehua[/eluser]
Thanks sinokada. [Yes, sorry, when I said "source" I meant the HTML source (View...Source) rather than the rendered browser view, if you know what I mean.] Not sure where the problem lies then. You said you're getting the error when you run Code: $totalprice = $_SESSION['totalprice']; And yet you don't get the error on running: Code: print_r ($_SESSION['totalprice'] And if you just Code: echo $_SESSION['shipping']; ? And how about Code: $shipping = $_SESSION['shipping']; Does that work OK?
[eluser]shinokada[/eluser]
As I said the error does not come out on the web site. But if I see the source it is there. I may be ignore the error. |
Welcome Guest, Not a member yet? Register Sign In |