0

I'm working on a ZF2 project, and using ZfcUser to manage website users. I just want to know is it possible to have a child route to the zfcuser route? Something like that, in the configuration of my module:

return [
        'router' =>
        [
            'routes' =>
            [
                'admin' =>
                [
                    'type'    => 'Segment',
                    'options' =>
                    [
                        'route'    => '/admin',
                        'defaults' =>
                        [
                            '__NAMESPACE__' => 'admin',
                            'controller'    => 'admin.index',
                            'action'        => 'index',
                        ],
                    ],
                    'may_terminate' => true,
                    'child_routes'  =>
                    [
                        'zfcuser' =>
                        [
                            'type' => 'Literal',
                            'options' =>
                            [
                                'route' => '/account',
                            ]
                        ],
                    ],
                ],

            ],
        ],
    ];
akond
  • 15,865
  • 4
  • 35
  • 55
user2711783
  • 65
  • 2
  • 10
  • What are you trying to do, point /admin/account to something that zfcuser provides? – Saeven Jan 25 '16 at 17:51
  • I implemented Zfcuser in my project. I now want to rewrite the routes of zfcuser, to properly integrate my project. And I want that the zfcuser routes are child routes of my admin route – user2711783 Jan 26 '16 at 08:21

1 Answers1

0

This is a problem I've tried overcoming recently, not using ZfcUser but whilst developing my own modules. There are a few solutions but the most suitable would depend on the type of application you're developing.

The easiest solution would be to override the zfcuser route path and prefixing it with admin.

return [
    'router' => [
        'routes' => [
            'zfcuser' => [
                'options' => [
                    'route' => '/admin/user',
                ],
            ],
        ],
    ],
];

If you're like me and want all you admin routes contained under a single route then you're better off removing the zfcuser route completely and implementing your own which could utilize the ZfcUser controllers.

namespace Application;

use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;

class Module
{
    public function init(ModuleManager $moduleManager)
    {
        $events = $moduleManager->getEventManager();
        $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'));
    }

    public function onMergeConfig(ModuleEvent $event)
    {
        $configListener = $event->getConfigListener();
        $configuration = $configListener->getMergedConfig(false);

        if (isset($configuration['router']['routes']['zfcuser']))
        {
            unset($configuration['router']['routes']['zfcuser']);
        }

        $configListener->setMergedConfig($configuration);
    }
}
adamdyson
  • 61
  • 1
  • 4
  • OK, thanks for the add. I will try this tonight, or tomorrow. Feedback soon ;-) – user2711783 Jan 26 '16 at 16:12
  • No worries, depending on what method you go with, just remember to override anything that references the old routes E.g. `zfcuser/logout`. – adamdyson Jan 27 '16 at 12:02