Keyword

Adding PHP Function to category_item.php breaks site template.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99258 by Dave Smith
I'm not sure what the issue here is, hope someone can help, I am trying to add a PHP function to my category_item.php

When I add the function, the site doesn't display correctly anymore.

 

The function can be stripped down as far as the following, and yet still breaks the site:

 

<?phpfunction myfunction($test){  return($test);}?>
 

Anyone help ?

 

thanks.

Please Log in or Create an account to join the conversation.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99259 by Dave Smith
Well, it appears that I have something dodgy in my category_item.php, as I added the same code to item.php and this works fine. Looks like a long debugging session is in order!

Please Log in or Create an account to join the conversation.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99260 by Dave Smith
Weird. Now it's all working. Never mind. Sorry to have bothered you.

Please Log in or Create an account to join the conversation.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99261 by Dave Smith
No, still not working, I'm fairly sure it is a missing closing tag somewhere (possibly a ?> ), but strange. It works fine if there is only one item in the category, but any more and it breaks...

Please Log in or Create an account to join the conversation.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99262 by Dave Smith
Right. Been through the W3C validator (at validator.w3.org) and removed 15 errors. The remaining 8 errors are caused by googlemaps scripts and Google/Facebook/Twitter buttons. These can be left alone. I did however add a missing </div> in my google map script output for the map label. This did not solve my problem. I also ran the "broken" page through the validator and it shed some light, it turns out the page is giving a 500 error which is being hidden by my template somehow - so I am not seeing it.

Please Log in or Create an account to join the conversation.

  • Dave Smith
  • Dave Smith's Avatar Topic Author
  • Offline
  • New Member
More
13 years 1 month ago #99263 by Dave Smith
SOLVED:

 

After getting the 500 error, I managed to get my Apache2 Error log working again by restarting apache2 on the server. (If it isn't one thing it's another!)

 

Error log showed me an interesting error: cannot re-declare function.

 

If anyone else has a similar problem, changing the original function above to read:

 

<?phpif (!function_exists("myfunction")){

    function myfunction($test)    {

        return($test);    }

}

?>

 

Solves this problem.

 

The problem is caused because the function is inside the category_item.php file, which is repeated each time an item is shown on the category page, therefore the second and subsequent time the item is shown the function is re-declared (which is not allowed!)

 

Hope this helps someone in future.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum