Empty Errors are Printing Out
Permalink 1 user found helpful
My view.php file is outputting the code as if it is displaying an error, except there are no errors to display. Here is the html that outputs:
And here is the section of my view.php file that should print errors if any exists:
I've been digging into this for days and can't figure out what's wrong. I do this the EXACT same way on every other site I build and non of them display the empty error tag.
Thoughts?
<ul class="ccm-error"> </ul>
And here is the section of my view.php file that should print errors if any exists:
<?php if (isset($error) && $error != '') { ?> <?php if ($error instanceof Exception) { $_error[] = $error->getMessage(); } else if ($error instanceof ValidationErrorHelper) { $_error = $error->getList(); } else if (is_array($error)) { $_error = $error; } else if (is_string($error)) { $_error[] = $error; } ?> <ul class="ccm-error"> <?php foreach($_error as $e) { ?><li><?php echo $e?></li><?php } ?> </ul>
Viewing 15 lines of 18 lines. View entire code block.
I've been digging into this for days and can't figure out what's wrong. I do this the EXACT same way on every other site I build and non of them display the empty error tag.
Thoughts?
What would vardump($error) accomplish?
It would show you exactly what is in the $error array.
Well I put vardump($error); after the opening IF statement, and now nothing shows up at all...just a blank content area.
Also, tracing out each of the possible errors in the else/if series, turns out there is a ValidationError somewhere...
Since it is a validation error the var dump will probably simply output the word object. Now that you know it is a validation error you can go and track down why your validation error checking is even being run. You may also want to place a var dump statement and expose exactly what is coming our of the $ error->getlist command.
You need to view the page source to see the output of vardump.. You can use printr () if you want it rendered.
I did check the page source...there was nothing at all in my content div where all of this code was placed.
Alright...so print_r($error) gives me this:
ValidationErrorHelper Object ( [error:protected] => Array ( ) )
And tracing out getList returns just an empty array.
No idea what that means....or how to fix it!
ValidationErrorHelper Object ( [error:protected] => Array ( ) )
And tracing out getList returns just an empty array.
No idea what that means....or how to fix it!
Why is validation checking even being performed. Do you only get this problem when you POST / GET something to this page, or does this happen when you first visit the page?
-Guy
-Guy
This is on every page the utilizes my view.php file (so the login page, profile page, all of the "Discussion" pages that come with the Discussion Forum addon).
I normally wouldn't even notice the empty error except I have the <ul class="error"> tag styled to have a red border around it, so it shows up all the time...but with nothing in it.
The error only shows up after a user is logged in. Visiting the login page for the first time works fine...after logging in I see this.
I normally wouldn't even notice the empty error except I have the <ul class="error"> tag styled to have a red border around it, so it shows up all the time...but with nothing in it.
The error only shows up after a user is logged in. Visiting the login page for the first time works fine...after logging in I see this.
Try replacing your code with this:
<?php if (isset($error) && $error != '') { ?> <?php if ($error instanceof Exception) { $_error[] = $error->getMessage(); } else if ($error instanceof ValidationErrorHelper) { if (!empty($error->getList())){ $_error = $error->getList(); } } else if (is_array($error)) { $_error = $error; } else if (is_string($error)) { $_error[] = $error; } if ($_error){ ?>
Viewing 15 lines of 22 lines. View entire code block.
That actually breaks the page. Any page utilizing the view.php file is just white with no source code to view.
I didn't test that code, so it must be invalid. Do you know why php isn't printing out any errors?
Probably because I have the site set to Production instead of Development.
So putting the site in Development mode spits out this when I use the code you gave me:
Fatal error: Can't use method return value in write context in /web/content/themes/greater-mn/view.php on line 94
Line 94 is this:
Fatal error: Can't use method return value in write context in /web/content/themes/greater-mn/view.php on line 94
Line 94 is this:
if (!empty($error->getList())){
Assign the getlist to a variable right above that line, then put the variable as the argument for the empty empty command. That should fix it.
Guy
Guy
That did the trick! Thanks, guythomas! For anyone who runs into this in the future, here is the working view.php code that I'm using based on the above info:
Though I still have no idea why there would be empty errors in the first place!
<?php if (isset($error) && $error != '') { ?> <?php if ($error instanceof Exception) { $_error[] = $error->getMessage(); } else if ($error instanceof ValidationErrorHelper) { $listError = $error->getList(); if (!empty($listError)){ $_error = $error->getList(); } } else if (is_array($error)) { $_error = $error; } else if (is_string($error)) { $_error[] = $error; } if ($_error){
Viewing 15 lines of 23 lines. View entire code block.
Though I still have no idea why there would be empty errors in the first place!
Yeah, it really is just a work around. Just make sure to do as much testing as you can to ensure that any actual errors are properly rendered. Especially validation errors like email addresses etc.
-Guy
-Guy
You should also figure out which of the nested if statements is running by echo ing a little identifier in each of the potential cases. That would be a good start to your troubleshooting.
Guy