开发者

How to pass global to Plugin in CakePHP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜