-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Missing instance/object for parameter route upgrading to 2.1.* #3625
Comments
Note: downgrading to 2.0.7 makes my application work again. Weird. :-/ |
Are you actually using Zend\Di in your application? If not, can you remove the config key for it and see if it works under 2.1.0? (Even if you are, try disabling it and accessing a route that does not use it.) Let me know what happens; if what I suspect is true, we'll need to create an FAQ for this. |
Weird, yes, you're right. Removing the 'di' section from my module config files allows my page to be viewable without the exception. And yes, I am using Zend\Di. I'd love to hear why this is.... |
There are two changes in 2.1.0 that could affect this. One, from @bakura10 makes the router's plugin manager an app-level plugin manager (like view helpers, controller plugins, etc); this might end up in it peering off the app's service manag , which could cause the bleed-over. The second change is that we eliminated the DI abstract factory as an initializer; @Ocramius might know if that would affect this. Once we know which is causing this, we can likely come up with a workaround. |
@weierophinney the initializer acts after |
Ah, btw, in |
I have the same problem, just upgraded and the server respons with a 500.... PHP Fatal error: Uncaught exception 'Zend\Di\Exception\MissingPropertyException' with message 'Missing instance/object for parameter route for Zend\Mvc\Router\Http\Literal::__construct' in /ucv/src/vendor/zendframework/zendframework/library/Zend/Di/Di.php:699\n Stack trace: |
@bakura10: currently on gprs... can you check if invokables come before
|
@alexz707 please provide a dump of
|
Mmh... Invokables always come before abstract factories. The route plugin manager is like any other plugin manager so it's invokables => factories => abstract factories. |
Yeah, but by default, invokables are added at runtime internally
|
@postalservice14 We really need to see your route, DI, and SM configuration to better diagnose and track down the issue. Any chance you can give us a scrubbed version of it that reproduces the problem? |
@alexz707 -- same goes for you -- any configuration examples you can give us will help us resolve the issue. |
@weierophinney Sorry about the delay. Here you go. module.config.php (excerpt) 'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'disableHomeScreen' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/disable-home-screen',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'disable-home-screen',
),
),
),
'login' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/login',
'defaults' => array(
'controller' => 'Application\Controller\Auth',
'action' => 'login',
),
),
),
'logout' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/logout',
'defaults' => array(
'controller' => 'Application\Controller\Auth',
'action' => 'logout',
),
),
),
'settings' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/settings',
'defaults' => array(
'controller' => 'Application\Controller\Settings',
'action' => 'index',
),
),
),
'select-project' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/project/select',
'defaults' => array(
'controller' => 'Application\Controller\Project',
'action' => 'select',
),
),
),
'select-contract' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/contract/select',
'defaults' => array(
'controller' => 'Application\Controller\Contract',
'action' => 'select',
),
),
),
'process-contract' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/contract[/:contract_id]/process',
'defaults' => array(
'controller' => 'Application\Controller\Contract',
'action' => 'process',
),
),
),
),
),
'di' => array(
'instance' => array(
'Application\Controller\Plugin\UserAuthentication' => array(
'parameters' => array(
'authAdapter' => 'Cmp\Authentication\Adapter',
'authService' => 'Zend\Authentication\AuthenticationService'
)
),
'Zend\Mvc\Controller\PluginLoader' => array(
'parameters' => array(
'map' => array(
'userAuthentication' => 'Application\Controller\Plugin\Authentication'
)
)
)
)
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Zend\Log' => function($sm) {
$log = new Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream('./data/logs/php.log');
$log->addWriter($writer);
return $log;
}
)
), Module.php (excerpt) public function getServiceConfig()
{
return array(
'factories' => array(
'Application\Model\SettingsTable' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new SettingsTable($dbAdapter);
return $table;
}
)
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'userIdentity' => function ($sm) {
$viewHelper = new View\Helper\UserIdentity();
$viewHelper->setAuthService(new \Zend\Authentication\AuthenticationService());
return $viewHelper;
},
'settingsHelper' => function ($sm) {
$locator = $sm->getServiceLocator();
$projectTable = $locator->get('Application\Model\SettingsTable');
$viewHelper = new View\Helper\SettingsHelper();
$viewHelper->setSettingsTable($projectTable);
return $viewHelper;
},
'version' => function ($sm) {
$locator = $sm->getServiceLocator();
$config = $locator->get('config');
$viewHelper = new View\Helper\VersionHelper();
$viewHelper->setVersion($config['version']);
return $viewHelper;
}
)
);
} |
You can work around this bug by calling them by shortname instead of the FQDN. <?php
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
etc...
?> |
@youngguns-nl thanks, I'll give that a try when I get home from work today. |
I've got a working test case reproducing the issue now; trying to see how to resolve the issue. |
@postalservice14 and @alexz707 -- I've got a PR in (#3640) which both verifies and resolves the issue. The workaround you can use until this is in the branch and/or in a release is to use the short route names instead of the fully qualified class names, as they do not trigger the issue. The fix I made was to override |
Thanks for looking into it and sorry for the delay! So when I use 'Literal' instead of 'Zend\Mvc\Router\Http\Literal' in my routes it should work again ? If that's the fix it wont work with my configuration :( what do you need from my config file? return array(
'controllers' => array(
'invokables' => array(
'Defaultpage\Controller\Index' => 'Defaultpage\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'defaultpage' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Defaultpage\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
//'may_terminate' => true,
),
),
),
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'base/index/index' => __DIR__ . '/../view/base/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
); thanks for your help Alex |
@alexz707 I've added a test demonstrating that pulling by short name works. Additionally, I ran this test both with and without the change to In your configuration above, wherever you have a Alternately, apply my patch to your working files. |
…nvokables - Prior to this patch, if a route has been registered as an invokable, but the DiAbstractServiceFactory was also present, using the FQCN to retrieve the route would result in DI being invoked. In the case of the various shipped ZF routes, this was undesirable, as the factory method for these classes was intended for instantiation; usage if DI caused failures. - This patch overrides the setInvokableClass() method of the router plugin manager such that it also calls setAlias() to alias the FQCN to the service name; this ensures that usage of the FQCN for a class already registered as an invokable will work properly.
- Added test demonstrating routes may be pulled by short names. Ran this test both before and after the setInvokableClass() change; passed in both cases.
When I upgraded my application to 2.1.* I got the following exception on my home page:
The text was updated successfully, but these errors were encountered: