Reputation: 1
Im new to zf2 and im trying to override the zfcuseradmin/useradmincontroller but its not working. I've tried many things but can't get it to work This is also my first post here so excuse me if its not correct in any way.
I've created a folder in the module folder called MyZfcUserAdmin I'm also using bjuauthorize, but don't know if thats important to know for you guys. The bootstrap is working, because the formfileds are added to my zfcuseradmin create form
here is my code:
module/MyzfcUserAdmin/config/module.config.php
return array(
'controllers' => array(
'invokables' => array(
'MyZfcUserAdmin' => 'MyZfcUserAdmin\Controller\MyZfcUserAdminController',
),
),
);
module/MyzfcUserAdmin/src/MyzfcUserAdmin/Controller/MyZfcUserAdminController.php
<?php
namespace MyZfcUserAdmin\Controller;
use ZfcUserAdmin\Controller\UserAdminController as BaseUserAdminController;
class MyZfcUserAdminController extends BaseUserAdminController
{
public function createAction()
{
$result = parent::createAction();
$form = $this->getServiceLocator()->get('zfcuseradmin_createuser_form');
$request = $this->getRequest();
$service = $this->getAdminUserService();
$messages = array();
if ($request->isPost())
{
$data = $request->getPost()->toArray();
$data['governance'] = 1;
if ($service->createasd($data) )
{
$messages[] = array(
'type' => 'success',
'icon' => 'icon-ok-sign',
'message' => 'succes',
);
return $this->redirect()->toRoute('zfcadmin/zfcuseradmin/list');
}
else
{
$messages[] = array(
'type' => 'error',
'icon' => 'icon-remove-sign',
'message' => 'failed',
);
}
}
return array(
'messages' => $messages,
'createUserForm' => $form
);
}
}
module/MyzfcUserAdmin/Module.php
<?php
namespace MyZfcUserAdmin;
use BjyAuthorize\Provider\Role\ZendDb AS rolesDb;
class Module
{
public $rights = array();
public $governance = array();
public function onBootstrap($e)
{
//get roles
$serviceManager = $e->getTarget()->getServiceManager();
$rolesdb = new rolesDb('', $serviceManager);
$roles = $rolesdb->getRoles();
$roleOptions = array('');
foreach($roles AS $role)
{
$name = $role->getRoleId();
if($name != 'guest')
$roleOptions[$name] = ucfirst($name);
}
$this->rights = array(
'name' => 'role',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => 'Rights',
'value_options' => $roleOptions,
)
);
$this->governance = array(
'name' => 'governance',
'options' => array(
'label' => 'Governance',
'checkedValue' => 1,
'uncheckedValue' => 0,
),
'attributes' => array(
'type' => 'checkbox',
),
);
$app = $e->getParam('application');
$em = $app->getEventManager()->getSharedManager();
$em->attach('ZfcUserAdmin\Form\CreateUser', 'init', function($e) {
$form = $e->getTarget();
//$form->add($this->rights);
$form->add($this->governance);
});
$em->attach('ZfcUserAdmin\Form\EditUser', 'init', function($e) {
$form = $e->getTarget();
// $form->add($this->rights);
$form->add($this->governance);
});
$em->attach('ZfcUserAdmin\Form\EditUserFilter','init', function($e) {
$filter = $e->getTarget();
// Do what you please with the filter instance ($filter)
});
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
Upvotes: 0
Views: 284
Reputation: 12809
You can just override the route in the module.config.php
Replace the controller with your default controller inside the route definition.
....
'zfcuser' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'myzfcuser',
//'controller' => 'zfcuser',
'action' => 'index',
),
),
Also check out the zfcuser.global.php config, there's route options in there you can modify
/**
* Login Redirect Route
*
* Upon successful login the user will be redirected to the entered route
*
* Default value: 'zfcuser'
* Accepted values: A valid route name within your application
*
*/
//'login_redirect_route' => 'zfcuser',
/**
* Logout Redirect Route
*
* Upon logging out the user will be redirected to the enterd route
*
* Default value: 'zfcuser/login'
* Accepted values: A valid route name within your application
*/
//'logout_redirect_route' => 'zfcuser/login',
Upvotes: 1