开发者

"Admin module" taking over Yii framework

开发者 https://www.devze.com 2022-12-21 17:56 出处:网络
I have an \"admin\" module and I want it to serve \"dynamic controllers\", i.e. to provide a default behaviour for controllers which don\'t really exist (\"virtual controllers\").

I have an "admin" module and I want it to serve "dynamic controllers", i.e. to provide a default behaviour for controllers which don't really exist ("virtual controllers").

I've invented a lightweight messaging mechanism for loose communication between modules. I'd like to use it such that when e.g.

?r=admin/users/index

is requested, it will call the "virtual controller" "UserController" of AdminModule, which would, by default, use this messaging mechanism to notify the real module "UsersModule" it can answer to the request.

I thought about simulating this behaviour in AdminModule::init(), but at that point I have no way of deciding whether the action can be processed by a real controller or not, or at least I don't know how to do it.

This is because of the way Yii works: bottom-up, the controller is the one that renders the view AND the application layout (or the module's, if it exists), for example. I don't think the module even has a word to say about handling a given controller+action or not.

To recap, I'm looking for a kind of CWebModule::missingController($controllerId,$actionId), just like CController::missingAction($actionId), or a workaround to simulate that.

That would possibly be in CWebModule::init() or somewhere w开发者_运维知识库here I can find out

  1. whether the controller actually exists, in which case it's his job to handle it
  2. the $actionID and $controllerID
  3. whether the module $controllerID exists (I didn't type it wrong, in r=admin/users/index, "users" is the actual module, as specified in the application's config).


I've found a solution http://www.yiiframework.com/forum/index.php?/topic/7569-admin-module-taking-over/page__view__findpost__p__38399

0

精彩评论

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