I am new to Zend Framework 2. I am running a project and I want its security to be managed by ZfcAdmin, ZfcUser, ZfcUserAdmin and BjyAuthorize. The first thing I'm trying to do is change the user creation process. I want to be able to assign roles to a new user immediately after creating it.
The first problem I encounter is when the user is created, the controller redirects me to the user list page. I need to change this behavior, I want to be redirected to the editing page, where I can select N roles for a newly created user (this will be another war with entities ...). I decided to override UserAdminController (ZfcUserAdmin). This is what I did for this:
1. I load my administrative module (MyAdministration) in last place in application.config.php to be able to override the properties of other modules.
2. I redefine the ZfcUserAdmin controller in MyAdministration / config / module.config.php to use mine:
(...) 'controllers' => array( 'invokables' => array( 'zfcuseradmin' => 'MyAdministration\Controller\MyAdministrationController', ), ), (...)
3. I created the class MyAdministration / SRC / MyAdministration / Controller / MyAdministrationController.php
4. I announced that it extends ZfcUserAdmin one
namespace Administracion\Controller; (...) use ZfcUserAdmin\Controller\UserAdminController; class AdministracionController extends UserAdminController { (...)
5. I redefined the createAction function to redirect to the edit page
(...) public function createAction() { (...) return $this->redirect()->toRoute('zfcadmin/zfcuseradmin/edit/:userId', array('userId' => $user->getId())); } (...)
What if I donโt know if I did it right. Network Search and Debugging I found out that there is a class called InjectTemplateListener that converts the Controller namespace to the path to the desired template. My controller is "transferred" to my administration / my administration / editing , which leads to nothing, the templates belong to the ZfcUserAdmin module. The correct path is the one received by its controller (ZfcUserAdmin \ Controller \ UserAdminController): ZFC-user-administrator / user-administrator / change
I also found out that template paths can be written manually. These paths are ignored by InjectTemplateListener. This is the approach I used. In MyAdministration / config / module.config.php I wrote:
(...) 'view_manager' => array( 'template_map' => array( 'my-administration/my-administration/list' => __DIR__ . '/../../../vendor/ZfcUserAdmin/view/zfc-user-admin/user-admin/list.phtml', 'my-administration/my-administration/create' => __DIR__ . '/../../../vendor/ZfcUserAdmin/view/zfc-user-admin/user-admin/create.phtml', 'my-administration/my-administration/edit' => __DIR__ . '/../../../vendor/ZfcUserAdmin/view/zfc-user-admin/user-admin/edit.phtml', 'my-administration/my-administration/pagination_userlist' => __DIR__ . '/../../../vendor/ZfcUserAdmin/view/zfc-user-admin/user-admin/pagination_userlist.phtml', ), (...) ),
I am not sure if this is the best way to achieve this. I believe that there should be a better way to do this, instead of manually writing template templates. I found a few things about overriding Controllers, and there are no examples ... Is this normal? Does anyone have a better approach to do redefinition?
Thanks!