Text Size

Members login

Recommend Print

Retrieving item data e.g. for use in RSforms

  • Published by
    Georgios Papadakis
  • Last modified
    10 May 2012
  • Up to date
    Yes
  • Profile concerned
    Developer
  • Concerns
    Component
  • Since Version
    1.5.6
  • Voting
    (2 votes)
  • Favourites
    Add to favourites

  1. Retrieving a basic field of the item, like title and category title:

    $db = & JFactory::getDBO();
    // Set a different item id if you don't want the current item ...
    $fcitem_id= JRequest::getInt('id',0);
    $fccat_id= JRequest::getInt('cid',0);
    $view= JRequest::getVar('view');
    if ($view!='items' && $view!='item' && $view!='article') {
       return "not in items view";
    }
     
    // RETRIEVE item data
    if ($fcitem_id) {
       $query = 'SELECT c.*'
          .' FROM '.'#'.'__content AS c '
          .' WHERE c.id = ' . $fcitem_id;
     
       $db->setQuery($query);
       $itemdata = $db->loadObject();
       $item_title = $itemdata->title;
    }
     
    // NOTE $itemdata now CONTAINS all item's basic fields
    // (but not values for FLEXIcontent fields)
     
    // RETRIEVE item's category data
    if ($fccat_id) {
       $query = 'SELECT c.*'
          .' FROM '.'#'.'__categories AS c'
          .' WHERE c.id = ' . $fccat_id;
     
          $db->setQuery($query);
          $catdata = $db->loadObject();
          $cat_title = $catdata->title;
    }
     
    // NOTE $catdata now CONTAINS all item's category basic fields
     
    // FINAL STEP: --IF-- your code is for using in a RSform field
    // then you need to return it:
    // so, USE ONE of the following return statements
     
    // e.g.
    return $item_title;
    //e.g.
    return $cat_title;
    // e.g.
    return $item_title ." - ".$cat_title;
     

     

  2. Retrieving the value of a custom field:

    $db = & JFactory::getDBO();
    // Set a different item id if you don't want the current item ...
    $fcitem_id= JRequest::getInt('id',0);
    $fccat_id= JRequest::getInt('cid',0);
    $view= JRequest::getVar('view');
    if ($view!='items' && $view!='item' && $view!='article') {
       return "not in items view";
    }
     
    $field_id=45;  // CHANGE THIS TO THE ID OF YOUR FIELD
    if ($fcitem_id) {
       $query = 'SELECT c.title, c.alias, f.value'
          .' FROM '.'#'.'__content AS c '
          .' LEFT JOIN '.'#'.'__flexicontent_fields_item_relations AS f'
          .' ON f.item_id = c.id AND f.field_id='.(int)$field_id 
          .' WHERE c.id = ' . $fcitem_id;
     
       $db->setQuery($query);
       $itemdata = $db->loadObject();
       $item_title = $itemdata->title;
    }
    return $itemdata->value; 
     

     

NOTE: Click to make this item favourable to be notified of updates

ALSO read this article:

-- Retrieving the HTML DISPLAY of FC fields inside 3rd-party code

Community

ggppdk : Online 201 mins yaK2manD : Online 318 mins xhyman : Online 424 mins algardata : Online 1068 mins netcoupe : Online 27260 mins
Members Online: 5

Latest Comments

Latest Forum Posts

Posted by xhyman - 17/05/2012 18:00
Posted by yaK2manD - 17/05/2012 17:51
Posted by ggppdk - 17/05/2012 17:47
Posted by yaK2manD - 17/05/2012 17:41
Posted by algardata - 17/05/2012 16:45
Posted by yaK2manD - 17/05/2012 14:56