Exception on attempt to retrieve ID Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
MaxK91
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Feb 04, 2019 6:58 pm

Exception on attempt to retrieve ID

Post by MaxK91 » Tue Feb 05, 2019 6:53 am

Hello, everyone!

I encountered the following problem.

When I tried to run the this code:

Code: Select all

$itemIdentifier = $input->get('id');	

function getArticleData($itemIdentifier = null)
	{
		if(!empty($itemIdentifier))
		{
			$article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($itemIdentifier);
			
			return $article;
		}
               
                return false
        }
I always get this error when I go to page where "com_phocagallery" is responsible for page rendering and not "com_content":
Error: Call to undefined method InvalidArgumentException::get(): Wrong controller class: ContentController
It seems error goes away if I use the following condition:

Code: Select all

if($input->get("view") == article)
{
	$itemIdentifier = $input->get('id');
}
So, as far as I can tell, the problem is with the component, because I'm trying to get ID from Application input, what's global thing. What's strange is that input on page where phocagallery works contains ID too, there is ID of phocagallery category though, meaning that get() should be available for use.

Could anyone give me a hint on this?
Last edited by toivo on Tue Feb 05, 2019 7:25 am, edited 2 times in total.
Reason: mod note: moved from General Questions/New to Joomla! 3.x - cross post removed, please read the forum rules from https://forum.joomla.org/viewtopic.php?f=8&t=65

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24982
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Exception on attempt to retrieve ID

Post by pe7er » Tue Feb 05, 2019 7:34 am

JControllerLegacy::getInstance('Content') tries to load the ContentController.
Joomla know where to find that controller on pages where com_content is active,
On other pages it doesn't know where to find it.

So you'll have to load the ContentController class
by adding the file with that class using JLoader::register before trying to "getInstance" it.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

MaxK91
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Feb 04, 2019 6:58 pm

Re: Exception on attempt to retrieve ID

Post by MaxK91 » Tue Feb 05, 2019 5:43 pm

pe7er wrote:
Tue Feb 05, 2019 7:34 am
JControllerLegacy::getInstance('Content') tries to load the ContentController.
Joomla know where to find that controller on pages where com_content is active,
On other pages it doesn't know where to find it.

So you'll have to load the ContentController class
by adding the file with that class using JLoader::register before trying to "getInstance" it.
Thanks for the reply! I'll take a closer look based on your advice! Thank you again!


Locked

Return to “Joomla! 3.x Coding”