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. 1 - backend as a separate
application: directory structure
wwwroot/
index.php
backend.php
[...]
protected/
config/
main.php
[...]
backend/
config/
main.php
[...]
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. 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. 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