Keyword

From another component retrieve extra fields of an item

  • roland
  • roland's Avatar Topic Author
  • Offline
  • New Member
More
2 weeks 14 hours ago #176364 by roland
Hi, on another component (SP page Builder addon modalpopup) I need to retrieve extrafields from a single K2 item. The code I write works fine on my local xampp environment but on the live web a 500 server error occurs when executing item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);

Am I using the correct syntax?

<?php
defined ('_JEXEC') or die ('Restricted access');
require_once(JPATH_SITE.'/components/com_k2/helpers/route.php');
require_once(JPATH_SITE.'/components/com_k2/helpers/utilities.php');

class SppagebuilderAddonModal extends SppagebuilderAddons{
public function render() {
$settings = $this->addon->settings;
$class = (isset($settings->class) && $settings->class) ? $settings->class : '';
...
$itemid = (isset($settings->modal_item_id) && $settings->modal_item_id) ? $settings->modal_item_id : '';
if (!$itemid == '') {
$db = JFactory::getDbo();
$query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams
FROM #__k2_items as i
LEFT JOIN #__k2_categories c ON c.id = i.catid
WHERE i.published = 1 AND i.access IN(1,1,5) AND i.trash = 0 AND c.published = 1 AND c.access IN(1,1,5) AND c.trash = 0
AND i.id=$itemid";
$db->setQuery($query);
$items = $db->loadObjectList();
// Render the query results
$model = K2Model::getInstance('Item', 'K2Model');
(array) $v = array();
if(count($items)) {
foreach($items as $item) {
...
$v["title"] = $item->title;
...
$item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
...
}
}
...

Best regards
Roland

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 weeks 14 hours ago #176366 by Fotis
What PHP version do you have on your local server vs the production one?

Attaching the entire PHP file would also help me more to debug/lint your code. Additionally, if you can call a model, there is no reason to execute direct SQL queries...

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

  • roland
  • roland's Avatar Topic Author
  • Offline
  • New Member
More
2 weeks 15 minutes ago #176376 by roland
Hi,

Sorry to have disturbed you. I have solved the problem, that wasn't one, by adding
if(!class_exists('K2ModelItem')) {
require_once ( JPATH_SITE . '/components/com_k2/models/item.php' );
}
so as to load 'function getItemExtraFields($itemExtraFields, &$item = null)'

and my component version in local PC xampp was not same as in the web site...sic...

problem closed :)

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
1 week 6 days ago #176385 by Fotis
Good to know :)

If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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


Powered by Kunena Forum