Welcome Guest, Not a member yet? Register   Sign In
Message: Undefined property
#1

[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...?
#2

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

[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;
#4

[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
#5

[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.
#6

[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...?
#7

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

Code:
error_reporting(E_ALL ^ E_NOTICE);
#8

[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
#9

[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 ??
#10

[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;




Theme © iAndrew 2016 - Forum software by © MyBB