Showing posts with label joomla. Show all posts
Showing posts with label joomla. Show all posts

Sunday, October 7, 2012

How to construct link to edit single zoo record


I'm writing this post because its quite tricky to create a link which edits a zoo record based on zoo item id unless you know how exactly zoo construct hashes.
When we asked on zoo forum they didn't reply with the following solution. I must admit that zoo component is excellent but their support is very poor & you know zoo support is paid! Okay leave it & lets move to the link.
Stop thinking that I'll pass zoo id to the zoo's my submission menu link to create edit record link. What?? have you tried it?? Does it says Hashes did not match. Alright Don't worry you are the right place.
Its very easy, you just need to pass submission type of zoo item & zoo item id itself to the getSubmissionHash API which returns you respective hash for the item.

$zapp = App::getInstance('zoo');
$items = $zapp->table->item->all(array('conditions' => 'id =$zoo_item_id)); 
//$zoo_item_id must be zoo record id which you want to edit.
$type = $items[$item->id]->type;
// get submission type of item
$hashRelated = $zapp->submission->getSubmissionHash(1,$type, $item->id); 
 // Here is the exact hash for the record

$href = JRoute::_(JURI::Base()."index.php?option=com_zoo&view=submission&layout=submission&submission_id=1&type_id=$type&item_id=$item->id&submission_hash=$hashRelated"); // Construct link as zoo 

echo '<a href=".$href.">Edit Record</a>';