Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:03:50+00:00 2026-06-09T00:03:50+00:00

As in title, I’m struggling to access DBAdapter inside Router. Implementing ServiceLocatorAwareInterface isn’t much

  • 0

As in title, I’m struggling to access DBAdapter inside Router. Implementing ServiceLocatorAwareInterface isn’t much help (ZF2 does not inject anything). Declaring it as a service in module with custom factory is not an option either, as it extends Http/Parts router and requires configuration parameters passed depending on a route (I don’t want to hard-code them)

What I’ve already tried:

module.config.php:

(...)
'router' => array(
    'routes' => array(
        'adm' => array(
            'type'    => 'Custom\Mvc\Router\Http\Segment',
            'options' => array(
                'route'    => '/admin[/:language[/:controller[/:action[/:params]]]]',
                'constraints' => array(
                    'language'  => '(pl|en)',
                    'controller' => "[a-zA-Z0-9_\-]*",
                    'action'     => "[a-zA-Z0-9_\-]*",
                    'params'        => "(.*)",
                ),
                'defaults' => array( ... ),
            ),
            'may_terminate' => true,
        ),
    ),
),
'service_manager' => array(
     (...)
    'invokables' => array(
        'Custom\Mvc\Router\Http\Segment' => 'Custom\Mvc\Router\Http\Segment',
    ),
),
(...)

As of now, Custom\Mvc\Router\Http\Segment is just a copy of Zend\Mvc\Router\Http\Segment, with added interfaces ServiceLocatorAwareInterface, AdapterAwareInterface and respective methods in the similar fashion:

public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
    var_dump($serviceLocator);
    exit();
}

It never enters the setServiceLocator method, only RouteInterface::factory(), which then calls constructor.

Setting up a factory didn’t help either, again – the code is not executed. Same behavior after moving the ‘invocables’ or factory to application config.

Currently using Zend Framework 2 RC1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:03:54+00:00Added an answer on June 9, 2026 at 12:03 am

    It would have been easier if you would have gisted us som code.. 🙂

    My recommendation would either be to use a factory to instansiate your custom router or set it as an invokable class (Requires you to implement ServiceLocatorAwareInterface so you can set it up in the router)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Title pretty much describes it, I just need to get all the order numbers
Title pretty much sums it up. Is there a technical name given to a
Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,
Title pretty much explains most of my question. I will provide some context. I've
Title pretty much covers it. If I've added say 3 objects to a list
Title pretty much explains it all, its the last thing I'm trying to work
Title says it pretty much all : is there a way to get the
Title pretty much nailed it, Im copying files to a flash drive and then
Title pretty much says it all. Right now it's using XML as the default
Title says all - what library(ies) or code or whatever does a digital audio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.