Question

I'm trying to re-use a plugin's controller method for adding a user (the plugin is usermgmt, a purchased plugin). The plugin's method does everything I need, however it finishes by doing a redirect to another page.

I don't want to modify the plugin code, and I am wondering if it is possible to temporarily disable the Controller:redirect method

class MyController extends AppController{
    function signUpUser(){
        //populate $this->request->data to be what plugin controller method is looking for

        //temporarily disable Controller::redirect

        //make call to plugin's controller method
        $usersController = new UsersController();
        $usersController->constructClasses();
        $usersController->addUser();

        //re-enable Controller::redirect

        //Do my own redirect
        $this->redirect('/welcome');
    }
}
Was it helpful?

Solution

You are not supposed to use controllers that way, there's probably a model or component which you could use instead. Extending the users controller may also be an option. Anyways, since you said you've bought it, why don't you contact the support, they should know best how their stuff works?

That being said, let me answer the actual question. In order to be able to disable redirection via your controller, you would have to override the Controller::redirect() method and implement some logic that allows you to disable the functionality.

Here's an untested example, it uses a property which defines whether redirects are enabled:

public $redirectEnabled = true;

public function redirect($url, $status = null, $exit = true) {
    if($this->redirectEnabled) {
        parent::redirect($url, $status, $exit);
    }
}

This should be pretty much self-explantory. In your controller you could set $this->redirectEnabled to true/false to enable/disable the redirect functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top