How to override/clone modules, which are downloaded to the vendor by composer in zf2?

前端 未结 2 2038
-上瘾入骨i
-上瘾入骨i 2021-01-27 07:34

SO!!!

I added zfcUser module (but I want to do this with any other module too) to my project, based on Zend Framework 2.*. How I can override controllers/vi

2条回答
  •  不知归路
    2021-01-27 07:54

    The best way to do this would be to create your own module to override everything you want to override. The views is easy, just add a subfolder called zfc-user in your module's view folder with a subfolder user, so you get YourModule/view/zfc-user/user In this custom views folder you can simply add your own versions of the ZfcUser templates: login.phtml, register.phtml etc.

    For this to work make sure your module is loaded after ZfcUser though. So in your config/application.config.php make sure YourModule comes after ZfcUser in the 'modules' array.

    To override the controllers just define your own UserController in your own module, either extending ZfcUsers's UserController or defining your own. Then have the routing take care of the rest. So in YourModule's module.config.php create routes pointing to your own UserController.

    Edit Add your custom UserController to your ZfcUserOverride module. Then add it to this same module's module.config.php to the service manager config and alias it with zfcuser which is the name ZfcUser uses.

    'controllers' => array(
            'invokables' => array(
                'zfcuser' => 'ZfcUserOverride\Controller\UserController',
            ),            
    ),
    

    Edit 2: Also don't forget to add this to your module.config.php:

    'view_manager' => array(
        'template_path_stack' => array(
            'zfcuser' => __DIR__ . '/../view',
        ),
    ),
    

    This is required if you're overriding ZfcUser's view scripts.

提交回复
热议问题