Zoo - one of the most popular Joomla extension has a view which shows just a single record, that is of course full view. Zoo doesn't have a view which shows a list of records of particular submission type. So what if you want to show a list of zoo items of particular type in your extension.
You must be thinking what's the big deal, based on submission id just fetch the records & show it how you want. Wait a minute. Its not as easy as you think as Zoo uses JSON method to store record's which is quite difficult to render zoo elements. So its quite complicated to get zoo items details from database by executing queries.
Even if you manage it won't be robust cause to get related records from table you have to deal with hard coded 36 key string, which zoo uses as field identifier. So lets get away from this hassle.
Here is the snippet to render the details of zoo records quite easily.
You must be thinking what's the big deal, based on submission id just fetch the records & show it how you want. Wait a minute. Its not as easy as you think as Zoo uses JSON method to store record's which is quite difficult to render zoo elements. So its quite complicated to get zoo items details from database by executing queries.
Even if you manage it won't be robust cause to get related records from table you have to deal with hard coded 36 key string, which zoo uses as field identifier. So lets get away from this hassle.
Here is the snippet to render the details of zoo records quite easily.
$zapp = App::getInstance('zoo'); $items = $app->table->item->all(array('conditions' => 'id = '.$Zoo_Item_id)); //$Zoo_Item_id must be zoo item id of which you want to render details foreach($items as $item) { foreach ($item->getElements() as $id => $element) { echo $element->render();Here you can see how we are showing Zoo related records in table. We have added link for full view of respective Zoo Item as well.
} }
Thank you. This is a nice piece of code.
ReplyDeleteCurious. I used this and supplied an item ID but ended up with a list of all the items of that type. What is the purpose of supplying the item ID if it pulls all the records?
My BIGGER question is .. in my code, how do I create a link to the full view of a specific item?
Hi Mich,
ReplyDeleteI have constructed link for full view as a mentioned below.
$link = JRoute::_(JURI::Base().'index.php?option=com_zoo&task=item&item_id=$Record_Id&category_id=$Category_Id&Itemid=112');
// $Record_Id should be zoo record id
// $Category_Id should be category of $Record_Id
Hope it helps you.