0

我是 zf2 的新手,我试图覆盖 zfcuseradmin/useradmincontroller 但它不起作用。我已经尝试了很多东西,但无法让它发挥作用这也是我在这里的第一篇文章,如果它有任何不正确之处,请见谅。

我在名为 MyZfcUserAdmin 的模块文件夹中创建了一个文件夹,我也在使用 bjuauthorize,但不知道这对你们来说是否重要。引导程序正在工作,因为表单文件已添加到我的 zfcuseradmin 创建表单中

这是我的代码:

模块/MyzfcUserAdmin/config/module.config.php

return array( 
'controllers' => array(
    'invokables' => array(
        'MyZfcUserAdmin' => 'MyZfcUserAdmin\Controller\MyZfcUserAdminController',
    ),
),

);

模块/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
    );   
}
}

模块/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__,
                ),
            ),
        );
    }


}
4

1 回答 1

1

您可以覆盖 module.config.php 中的路由

将控制器替换为路由定义中的默认控制器。

....
'zfcuser' => array(
            'type' => 'Literal',
            'priority' => 1000,
            'options' => array(
                'route' => '/user',
                'defaults' => array(
                    'controller' => 'myzfcuser',
                    //'controller' => 'zfcuser',
                    'action'     => 'index',
                ),
            ),

另请查看 zfcuser.global.php 配置,您可以在其中修改路由选项

/**
 * 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',
于 2013-02-14T11:54:49.927 回答