I would like to extend the (un)publish-function in a sub controller.

I thought it would be enough to write something like that to my sub controller items.php:

    public function unpublish()
        echo "Test";

But on unpublishing my items nothing happens. What can I do here?


Take a look at JControllerAdmin what is used to extend your controller.

In __construct function on line 62 unpublish is set to use publish function. So there is no function like unpublish.

And in publish function you can get task name with $task = $this->getTask();.

Possible values are publish, unpublish, archive, trash and report. So you can compare, if it is publish or unpublish and make actions based on that.

Your function could look like this:

public function publish()
    $task = $this->getTask();

    // Do your custom actions
    if($task == 'unpublish'){
        // Do something on unpublishing item(s)
    }else if($task == 'publish'){
        // Do something on publishing item(s)

    // Call parent function, so item(s) will get published/unpublished like they are used to

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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