ryanrk wrote
> I'm playing around with ZF2 coming from ZF1 and I'm having an issue with
> adding new controllers and actions. My module doesn't seem to find them.
> I started from the Zend Skeleton.
>
> module.config.php looks like
> .
> 'application' => array(
> 'type'=> 'Literal',
> 'options' => array(
> 'route'=> '/application',
> 'defaults' => array(
> '__NAMESPACE__' => 'Application\Controller',
> 'controller'=> 'Index',
> 'action'=> 'index',
> ),
> ),
> 'may_terminate' => true,
> 'child_routes' => array(
> 'default' => array(
> 'type'=> 'Segment',
> 'options' => array(
> 'route'=> '/[:controller[/:action]]',
> 'constraints' => array(
> 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
> 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
> ),
> 'defaults' => array(
> ),
> ),
> ),
> ),
> ),
> .
>
> I added controllers/TestController.php,
> view/application/test/index.phtml and duplicated what was in
> indexcontroller or index.phtml while changing the class names.
>
> When I go to http://localhost/application/test/ i just get
>
> The requested controller could not be mapped to an existing controller
> class.
> Controller:
> Application\Controller\Test(resolves to invalid controller class or alias:
> Application\Controller\Test)
> Exception:
> Zend\ServiceManager\ServiceManager::get was unable to fetch or create an
> instance for Application\Controller\Test
>
>
>
> In ZF1 this would have worked, am I missing something?
Remember to add your controller class to invokables in your module config:
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' =>
'Application\Controller\IndexController',
'Application\Controller\Test' =>
'Application\Controller\TestController' // add this line
),
),
Without this your application doesn't know about the TestController you've
added.
-
Cheers,
--
Luke Mierzwa
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZF2-and-understanding-routes-tp4657579p4657581.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com