Keyword

Fatal error: Cannot redeclare class K2ModelItem

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago - 11 years 10 months ago #66294 by Aimery Marsily
Fatal error: Cannot redeclare class K2ModelItem was created by Aimery Marsily
Hi,

I need to create a new plugin for K2, for that I use the trigger "onAfterK2Save" and I add this code in my function to get the extrafield formated :
Log in  or Create an account to join the conversation.

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago #66295 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Fatal error: Cannot redeclare class K2ModelItem
I realy need to use the function getItemExtraFields in my plugin but it's a nightmare !

If I undersant the error is because the model item.php is already called on saving a K2 item... I can't see how to call the function...

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

More
11 years 10 months ago #66296 by Leon TuckingFypo
Replied by Leon TuckingFypo on topic Re: Fatal error: Cannot redeclare class K2ModelItem
I am having a fatal error as well, and the lines seems same (require once... is same )

require_once(JPATH_SITE.DS.'components'.DS.'com_mailto'.DS.'helpers'.DS.'mailto.php');
$item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link='.MailToHelper::addLink($item->absoluteURL));

This is at view.html.php file..

I think something is wrong with the new version of K2 ( Probably a bug ). THEY NEED TO FIX IT!

Because i kept an older version of K2, were everything is ok, i saw that the line which starts with "require once",wasn't there. So dunno, something is wrong with the new version.

P.S This error gives me php error message when i try to see a k2 item.

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

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago #66297 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Fatal error: Cannot redeclare class K2ModelItem
I hope the K2 team will make quickly an update to fix that or give us a way to work around... HELP ;)

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

More
11 years 10 months ago #66298 by JoomlaWorks
Replied by JoomlaWorks on topic Re: Fatal error: Cannot redeclare class K2ModelItem
We'll have a look and get back to you guys.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
11 years 10 months ago #66299 by Lefteris
@Mushr00m

This is happening because you are including the front-end item model which has the same class name as the backend item model, which is already loaded to perform the save. Try to use JModel to access the model. Something like this may do the trick:

JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'models');
$model = JModel::getInstance('Item', 'K2Model');

If this don't solve the issue then just enbody the function to your plugin, there is no other way.

@Leon TuckingFypo

Can you please be more specific? The fact that this is the same kind of error ( require once failure ) does not mean that it is the same error. It would be very helpful if you post the entire error message here.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago - 11 years 10 months ago #66300 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Fatal error: Cannot redeclare class K2ModelItem
Thanks for your help and your time.

Unfortunately I got this message now :
Fatal error: Call to undefined method K2ModelItem::getItemExtraFields()

If you know how to fix it ?

NB : I did that to create the model :
JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'models');
$model2 = JModel::getInstance('Item', 'K2Model');
And I call the function like this : $result->extra_fields = $model2->getItemExtraFields($result->extra_fields);

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

More
11 years 10 months ago #66301 by Lefteris
It seems that Joomla! still gives you the backend model. Unfortunatelly there is no way to use the front-end model when the backend model is already loaded, since they share the same class name. The only thing you can do is to enbody the function to your plugin.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago #66302 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Fatal error: Cannot redeclare class K2ModelItem
I tried to do that but with the function embeded to get the extrafield, I must call the helper "utilities.php" from K2 and doing that I have this error now :
Fatal error: Call to undefined method JAdministrator::getParams()

So utilities.php call this : $params = &K2HelperUtilities::getParams('com_k2');
That call this (and that's where it dies) : $params = & $app->getParams($option);

Sorry for the nightmare but I don't get it at all :unsure:

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

  • Aimery Marsily
  • Aimery Marsily's Avatar Topic Author
  • Offline
  • Premium Member
More
11 years 10 months ago #66303 by Aimery Marsily
Replied by Aimery Marsily on topic Re: Fatal error: Cannot redeclare class K2ModelItem
So I found a workaround to get the K2 params instead of using K2 utilities.php helper I call :
$params = JComponentHelper::getParams('com_k2');

It works but I don't know if it's the "good" way ?

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