Book Image

Learning Joomla! 1.5 Extension Development

Book Image

Learning Joomla! 1.5 Extension Development

Overview of this book

Table of Contents (17 chapters)
Learning Joomla! 1.5 Extension Development
Credits
About the Author
About the Reviewer
Preface

Editing records


Instead of writing a whole new set of functions for editing records, we can extend the existing code for the single view. In the views/single/view.html.php file, add the code highlighted below under $row =& JTable::getInstance ('Review', 'Table'):

function display($tpl = null)
{
$row =& JTable::getInstance('Review', 'Table');
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$id = $cid[0];
$row->load($id);

$this->assignRef('row', $row);
$editor =& JFactory::getEditor();
$this->assignRef('editor', $editor);
}

As we did with the save() function in RestaurantsController, we get a TableReview object to handle the data for the record. We also pull in the form variable cid, which is an array of record IDs. Because we only want to edit one record at a time, we select the first ID in the array and load the corresponding row. This is all we have to do in order to populate the single view with data from the jos_reviews table.

To make the edit task active...