Download the PHP package dmstr/yii2-themed-view-path-behavior without Composer
On this page you can find all versions of the php package dmstr/yii2-themed-view-path-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-themed-view-path-behavior
yii2-themed-view-path-behavior
Behavior to easily set additional view paths via yii2 theme pathMap.
Config options see: ThemedViewPathBehavior.php
ThemedViewPathBehavior can be attached to:
- controllers
- modules
- widgets
path order
As the yii\base\Theme will use the first matching view file from the list of given paths, the order within the generated pathMap is relevant.
In the context of this behavior, there are basically 2 scenarios:
Should the owners default viewPath be the first or the last directory where yii will search for view files?
The pathOrder
property can be used to define the order:
value | effect |
---|---|
ThemedViewPathBehavior::MAP_APPEND | the owners default viewPath will be the first dir in map |
ThemedViewPathBehavior::MAP_PREPEND | the owners default viewPath will be the last dir in map |
used Events
According to the type of the owner
the behavior attach itself to events:
owner | event |
---|---|
controller | Controller::EVENT_BEFORE_ACTION |
module | Module::EVENT_BEFORE_ACTION |
widget | Widget::EVENT_BEFORE_RUN |
Examples:
Extend viewPath for one controller
Task:
- You have installed the dmstr/yii2-active-record-search
- You want to integrate a SearchGroupController to manage the SearchGroups from active-record-search module within another module e.g. admin
- You want to overwrite some (but not all) default views used from within \dmstr\activeRecordSearch\controllers\SearchGroupController
Solution:
- set active-record-search module view path as fallback via behavior config.
generated pathMap for ProductController:
Extend view Path for all (child) controllers via BaseController
Task:
- You have an admin module where you define controllers to manage AR Models created with giiant within a cruds module
- Your admin controllers have names (ids) that are also defined in the cruds module
- You want to overwrite some (but not all) default views from the generated cruds
Solution:
- add behavior to a BaseController used by Controllers which should use the views from the cruds module as fallback and define the basePath as pathMap.
- the controller ID will be appended within behavior
generated pathMap for ProductController:
Extend view Path for all (child) controllers via BaseController with "branded" subDirs
Task:
- same as above, but with additional subdir(s) where you can store "branded" views
Solution:
- same as above, but add another path with "branded" name
generated pathMap for ProductController:
add extended view path for all controllers via Module
Task:
- you have a module with default (e.g. autogenerated) view files in the default
./views/
dir of the module - you want to overwrite some (but not all) default views with files in a
./views-extended/
dir of the module
Solution:
- add behavior to the Module class
- define the *-extended dir in
pathMap
- set the
pathOrder
toThemedViewPathBehavior::MAP_PREPEND
as yii should search first in the given./views-extended/
and use the default viewPath as fallback
generated pathMap for Controllers within this module:
add alternative branded/themed view path for a widget
Task:
- you have a widget and want to overwrite (some) views according to defined brand via subdirs per brand
Solution:
- add behavior to the Widget class
- define subDirs for current context (via ApplicationHelper::brand() in this example)
generated pathMap for the widget: