CodeIgniter Forums
Message: Undefined property - 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: Message: Undefined property (/showthread.php?tid=7129)

Pages: 1 2


Message: Undefined property - El Forum - 03-25-2008

[eluser]a.somervell[/eluser]
So i've got a site-wide view like this:

Code:
<? if($this->session->flashdata("message")) { ?>
                        <div class="flash_message">
                            <ul>
                                &lt;?=$this->session->flashdata("message")?&gt;
                            </ul>
                        </div>
&lt;? } ?&gt;

And on pages where flashdata isnt set I get "Message: Undefined property" which is just a PHP notice, but I spose PHP notices are there for a reason...

if(isset(...)) doesnt work... what if test will work for this...?


Message: Undefined property - El Forum - 03-26-2008

[eluser]Pascal Kriete[/eluser]
Code:
&lt;? $msg = $this->session->flashdata('msg'); if ($msg): ?&gt;
&lt;?= $msg ?&gt;</span>
&lt;? endif; ?&gt;



Message: Undefined property - El Forum - 03-26-2008

[eluser]wiredesignz[/eluser]
My turn to improve code :lol:
Code:
&lt;? if($msg = $this->session->flashdata('msg')): ?&gt;
&lt;span class="flash_message">&lt;?= $msg ?&gt;</span>
&lt;? endif; ?&gt;



Message: Undefined property - El Forum - 03-26-2008

[eluser]a.somervell[/eluser]
1. Its an unordered list with bullet points (inside a big visible div) so whats this span business?? :p
2. Ok so that code isnt as much of a problem as the following ('cause the validation class isnt loaded in every page but I want this code in the global template)

Code:
&lt;?    if($msg = $this->validation->error_string) { ?&gt;
                        <div class="form_error">
                            <div class="title">Attention:</div>
                            <ul>
                                &lt;?=$msg;?&gt;
                            </ul>
                        </div>
&lt;?    } ?&gt;

I get

Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: messages/validation_error.php

Line Number: 1



Message: Undefined property - El Forum - 03-26-2008

[eluser]xwero[/eluser]
Have you loaded the validation library before you call that view? I guess you didn't and that is causing the error.


Message: Undefined property - El Forum - 03-26-2008

[eluser]a.somervell[/eluser]
Well no, this is in the global template, loaded by every page, and I only want to show the message if the validation class has been loaded and iff there's an error string.

Is there no way to have an if statement that checks for that? I mean I know why its giving me the error (which as I say is only a PHP notice, I could just turn 'em off haha! But I want the if statement to check for that...?


Message: Undefined property - El Forum - 03-26-2008

[eluser]GSV Sleeper Service[/eluser]
you could just cheat...

Code:
error_reporting(E_ALL ^ E_NOTICE);



Message: Undefined property - El Forum - 03-26-2008

[eluser]wiredesignz[/eluser]
Nice to see another Kiwi on CI forums too.

There is something odd there, you appear to have a custom validation_error class causing problems?

I have never seen a CI file named validation_error.php


Message: Undefined property - El Forum - 03-26-2008

[eluser]a.somervell[/eluser]
GSVSS: Heh yeah exactly

Wiredesignz: Yeah mate there are a few of us on here Wink - Its not a custom class, its just a view that has the above code in it, just to keep it all pretty + shit :p

This is what I dont get, you can have isset() for an array, surely there's *something* that works for this ??


Message: Undefined property - El Forum - 03-26-2008

[eluser]wiredesignz[/eluser]
Oh ok, I see now. Yes, you can check if the validation class is loaded quite easily.

Code:
&lt;?    if(isset($this->validation) AND $msg = $this->validation->error_string) { ?&gt;
                        <div class="form_error">
                            <div class="title">Attention:</div>
                            <ul>
                                &lt;?=$msg;?&gt;
                            </ul>
                        </div>
&lt;?    } ?&gt;