update docs

This commit is contained in:
Antonio Ramirez
2017-06-12 13:27:02 +02:00
parent b712514e30
commit c19646bf74
11 changed files with 201 additions and 30 deletions

View File

@ -0,0 +1,48 @@
Overriding Controllers
======================
Maybe you need to override the default's functionality of the module's controllers. For that, as you probably know,
Yii2 Modules have an attribute named `controllerMap` that you can configure with your very own controllers.
Please, before you override a controller's action, make sure that it won't be enough with using the
(controller's events)[../events/controller-events.md].
> See more about this attribute on
> [ The Definitive Guide to Yii 2.0](http://www.yiiframework.com/doc-2.0/guide-structure-controllers.html#controller-map)
How to Override
---------------
First, create your new controller:
```php
namespace app\controllers;
use Da\User\Controller\RegistrationController as BaseController;
class ProfileController extends BaseController {
public function actionConfirm($id, $code) {
// ... your code here
}
}
```
Now, the only thing that is missing is to add your brand new controller to the module's controller's map:
```php
'modules' => [
// ...
'user' => [
'class' => 'Da\User\Module',
'controllerMap' => [
'profile' => 'app\controllers\ProfileController'
]
]
]
```
© [2amigos](http://www.2amigos.us/) 2013-2017

View File

@ -20,7 +20,7 @@ Bootstrap), Yii2 provides a mechanism that is really easy to do:
The above code tells Yii2 to search on `@app/view/user` for views prior to go to `@Da/User/resources/views`. That is,
if a view is found on `@app/view/user` that matches the required render it will be displayed instead of the one on
`@Da/User/resources/views`.
`@Da/User/resources/views`.
You need to remember that the folder structure on your new location must match that of the module. For example, if we
wish to override the `login.php` view using the above setting, we would have to create the following structure on our
@ -38,4 +38,17 @@ app [ Your root ]
See how it follows the same structure as within the User's module `resources/views` path? Well, that's what you should
do with any of the others in order to override them.
There is another way, and is by setting the `viewPath` attribute of the module:
```php
'modules' => [
'user' => [
'class' => Da\User\Module::class,
'viewPath' => '@app/views/user'
],
],
```
But it will force you to override **ALL** views from the module. The recommended way is throughout the `theme` property
of `view` component as previously mentioned.
© [2amigos](http://www.2amigos.us/) 2013-2017