开发者

How to pass global to Plugin in CakePHP

开发者 https://www.devze.com 2023-01-25 03:22 出处:网络
I have a global object in my main controllers that I need to pass to a plugin controller, how do I achieve this and resolve th开发者_如何学Goe scope?If you speaking about global object placed in app_c

I have a global object in my main controllers that I need to pass to a plugin controller, how do I achieve this and resolve th开发者_如何学Goe scope?


If you speaking about global object placed in app_controller.php of your application, then it's very easy, because all plugins extend AppController class. Basically what would be your code:

class AppController extends Controller {
   function beforeFilter(){
      $this->global_object = ... //the global object instance.
   }
}

Then because your plugin's AppControler extends applications's AppController you can access it in all plugin's controllers functions. For example:

class YourPluginAppController extends AppController {
    function doSomethingWithGlobalObject(){
        $this->global_object->doSome();//
    }
}

Hope this is what you asked.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号