Yii backend sub-modules

4,431 views
4,128 views

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,431
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
21
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Yii backend sub-modules

  1. 1. Backend sub-modules Yet another approach to Yii backend development by Giovanni Derks - http://derks.me.uk
  2. 2. Common approaches & main benefits 1. backend as a separate application a. b. c. d. separate user session separate entry script / configuration possibility to share models, components, etc. between frontend and backend better organisation of the code 2. backend as a module a. b. c. d. single entry script ability to reuse code designed for both environments more suitable for small sized projects common urlManager rules between frontend and backend
  3. 3. 1 - backend as a separate application: directory structure wwwroot/ index.php backend.php [...] protected/ config/ main.php [...] backend/ config/ main.php [...]
  4. 4. 2 - backend as a module: directory structure wwwroot/ index.php [...] protected/ config/ main.php backend.php [...] modules/ admin/ components/ controllers/ views/
  5. 5. Our implementation: Backend sub-modules wwwroot/ index.php [...] protected/ [...] modules/ admin/ [...] modules/ module1/ controllers/ [...] module2/ controllers/
  6. 6. Advantages of using sub-modules All the advantages of having the backend as a module, plus: ● ● common codebase for all admin sub-modules sub-modules are loaded by the main (parent) admin module. ○ same benefits as the backend as a separate application: ■ ■ ■ ■ sub-modules configuration is loaded automatically with the module modular backend so you can reuse the bits you need in other projects ○ ● separate user session shared backend components better organisation of the code …
  7. 7. Conventions ● ● ● the admin module is the parent module for the backend that handles all the backend (sub-) modules; the admin module will have only one (the default) controller, called AdminManagerController; backend modules ○ are submodules nested inside the admin module; ○ rely on a default controller named Admin<SubModuleName>Controller; ○ are loaded dynamically by the admin module that loads also the backend module configuration, if any; ○ configuration is stored under /protected/modules/admin/config/moduleName.php; ○ are accessed via /admin/subModuleName/actionName. If no controller is specified, the default controller of the module will be used; ○ can access different controllers via /admin/subModuleName/controllerName/actionName.
  8. 8. Drawbacks and limits ● ● ● ● ● adds complexity requires a custom url rule (class extending CBaseUrlRule) main admin module can use only a predefined controller sub-modules aliases are shared among all the project designed to work with 1 level of modules nesting
  9. 9. References 1. 2. 3. http://www.yiiframework.com/wiki/33/organize-directories-for-applications-with-front-end-andback-end http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/ http://www.yiiframework.com/forum/index.php/topic/27466-best-approach-for-backend-frontenddevelopment-in-yii/page__p__132209#entry132209

×