Sometimes our restaurant critics will want to remove their old drafts, and reviews of restaurants that have closed. Once again, adding a function to the RestaurantsController
class in /administrator/components/com_restaurants/restaurants.php
will power the Delete button in the toolbar seen in the all
view. Open that file and add the following remove()
function:
function remove() { JRequest::checkToken() or jexit( 'Invalid Token' ); global $option; $cid = JRequest::getVar('cid', array(0)); $row =& JTable::getInstance('review', 'Table'); foreach ($cid as $id) { $id = (int) $id; if (!$row->delete($id)) { JError::raiseError(500, $row->getError() ); } } $s = ''; if (count($cid) > 1) { $s = 's'; } $this->setRedirect('index.php?option=' . $option, 'Review' . $s . ' deleted.'); }
Notice that although the name of the JToolBarHelper
member function that generates the Delete button is deleteList()
, the button is passing in the task remove
when it is clicked. Because...