Notice: Trying to get property of non-object in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Purrfectlyyappy
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2014 3:17 am

Notice: Trying to get property of non-object in

Post by Purrfectlyyappy »

Hi Guys,

I'm working with a joomla site using Hikashop and I'm getting the following message at the top of my screen at the checkout on our website.

Notice: Trying to get property of non-object in /var/www/vhosts/purrfectlyyappy.com/httpdocs/templates/purrfectlyyappy/index.php on line 10
Notice: Trying to get property of non-object in /var/www/vhosts/purrfectlyyappy.com/httpdocs/templates/purrfectlyyappy/index.php on line 11
Notice: Trying to get property of non-object in /var/www/vhosts/purrfectlyyappy.com/httpdocs/templates/purrfectlyyappy/index.php on line 12

This does not apply on any other page on the site apart from the checkout page.

These are the first 13 lines of our index.php code for the site

Code: Select all

<?php

defined('_JEXEC') or die;
$app = JFactory::getApplication();
$leftbar = 1;
$rightbar = 1;
//$active = JFactory::getApplication()->getMenu()->getActive();
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$menuname = $active->title;
$parentId = $active->tree[0];
$parentName = str_replace(" ","",strtolower($menu->getItem($parentId)->title));
?>
Any ideas why im getting these warnings? Apologies i am a PHP n00b!!

Thanks

Sam
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Notice: Trying to get property of non-object in

Post by Celauran »

$active isn't an object. What is it?
Purrfectlyyappy
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2014 3:17 am

Re: Notice: Trying to get property of non-object in

Post by Purrfectlyyappy »

I'm not sure what you mean by that? If i were to remove this from the code, what would it affect?

Like i said, apologies but i've never dealt with php before :p
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Notice: Trying to get property of non-object in

Post by Celauran »

I mean this, basically

Code: Select all

<?php

defined('_JEXEC') or die;
$app = JFactory::getApplication();
$leftbar = 1;
$rightbar = 1;
//$active = JFactory::getApplication()->getMenu()->getActive();
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
var_dump($active); exit;
What's the output?
Purrfectlyyappy
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2014 3:17 am

Re: Notice: Trying to get property of non-object in

Post by Purrfectlyyappy »

I tried making that change above within the code but when i loaded the web page its just said 'NULL' so i haven reverted back to previous code.

This is the url for the page and you can see the exact notice that i am getting at the top of the page - maybe this will help?

https://www.purrfectlyyappy.com/index.p ... p/checkout

Thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Notice: Trying to get property of non-object in

Post by Celauran »

null is what $menu->getActive() is returning, which is the source of this particular problem. I'll let someone more familiar with Joomla! try to figure out why, as I have no experience with it and their documentation is a mess.
Purrfectlyyappy
Forum Newbie
Posts: 4
Joined: Wed Sep 24, 2014 3:17 am

Re: Notice: Trying to get property of non-object in

Post by Purrfectlyyappy »

Okay, thanks a lot for your help!
Post Reply