I have a course listing component, and each course as zero, one, or more corresponding sections for that course. Basically different versions of that course that run at different times at different locations.

If an administrator tries to delete a course, I'd like my component to first check for corresponding sections and if there are sections, prompt the user that those should be deleted or reassigned first before deleting the course itself.

Sorry, I've looked around and haven't found much documentation on this specifically. I'm somewhat new to Joomla MVC development as well.

Thank you very much!

EDIT: Starting to think that I have to override the default JControllerAdmin delete() function (I think that's what it is) and telling it to run a SELECT statement, and then whether or not there are matching sections, run or don't run the actual delete action. Hmm..

EDIT 2: The above thought seems to be the case, as I now have a delete() function in the controller that shows a JS alert when the delete button is hit.

1 Answer 1


You'd add a delete() method to your object's model, and do what you need to do in there. For example:

defined('_JEXEC' ) or die( 'Restricted access');

class myCourse extends JModelLegacy

public function delete($pks)
    // Initialise variables.
    $table  = $this->getTable();
    $pks    = (array) $pks;

    // do checks for corresponding data in here
    // code code code 
    // end check code stuff

    // Attempt to change the state of the records.
    if (!$table->delete($pks)) {
        // throw error
    // do something else if needed like return success message or enqueue message
  • It looks like you are "here to stay". Any chance of you swapping your generated username to something with personality? (If you are in witness protection and need to stay anonymous for your own safety, I understand. ) Feb 3, 2019 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.