Reputation: 4321
return array(
'router' => array(
'routes' => array(
'wall' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/api/wall[/:id]',
'constraints' => array(
'id' => '\w+'
),
'defaults' => array(
'controller' => 'Wall\Controller\Index'
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'Wall\Controller\Index' => 'Wall\Controller\IndexController',
),
),
);
I am looking at the configuration for a module Wall which is part of a JSON restfull API program with Zend Framework 2. In /myprogram/Wall/src/Controller directory there is a file IndexController.php and inside it the namespace is declared 'namespace Wall\Controller'. My question is about 'invokables'. The right hand side of '=>' makes sense to me it is referencing the controllers class name and namespace if I understand correctly. What is on the left hand side of '=>' I am still looking for an explanation of what is 'Wall\Controller\Index'.
Thank you for posting...
Upvotes: 1
Views: 1660
Reputation: 16455
It's really just a key
. Arrays within the configuration are stored with the schema key => value
. And the string Module\Controller\Foo
is just it's name. You could write module-controller-foo
, too, and use it like this within your route configuration.
Upvotes: 4
Reputation: 3442
invokables
defines classes you can call. You would usually define classes that can be invoked like this:
'invokables' => array(
'Some\Namespace\Class',
'Some\Namespace\OtherClass',
),
You can also define aliases, by passing an array, like in the example you gave:
'invokables' => array(
'Wall\Controller\Index' => 'Wall\Controller\IndexController',
),
It defines Wall\Controller\Index
invokable as an alias for Wall\Controller\IndexController
.
Upvotes: 5