1
votes

I'm using spark_plug plugin on cakephp, this plugin provides an authentication-acl system for register and admin users in cakephp. I want to add some new code and functionalities to the user's controller but I don't want to change the "main" plugin files.

I was thinking if it is possible leave the "main" plugin controller as it (unchanged) "\app\plugins\spark_plug\controllers\users_controller.php" and create a secondary controller with all the new code and functionalities, something like this "\app\controllers\users_controller.php" and extends the plugin "main" controller.

Is that possible? and how achieve that?

Or do you think is there any other way to do what I want?

Thanks!

1

1 Answers

0
votes

You could perhaps use composition rather than inheritance? I.e. create a "app\controllers\users_controller" that has inside it an instance of the plugin's controller. The UsersController passes through any unmodified actions via stubs, eg:

class UsersController extends AppController {

   ...

   var spark_plug_users_controller;  

   ...

   public function __construct() {
    parent::__construct();

    App::import('Controller', 'SparkPlug/Users'); // this is probably wrong.
        $this->spark_plug_users_controller = new UsersController; // as is this.
        $this->spark_plug_users_controller->constructClasses();
   }

   ...

   //example non-overridden method
   function login() {
      return $this->spark_plug_users_controller->login();
   }

   ...

}

your problem would be accessing protected/private methods within the spark_plug Users controller. But if you did not need to, this may work.