Automatic convention-based routing within a module in Zend Framework 2--possible? -
i'm trying understand configuration necessary routing working in zend framework 2, , can't wonder if making more complicated necessary.
i working on simple app follow simple convention:
/:module/:controller/:action
i've created , wired module, "svc" (short "service)". created second controller, "clientscontroller", , can't routing pass through requests to, e.g., /svc/clients/list clientscontroller::listaction().
as i'm wading through hundreds of lines of configuration, in nested arrays, i'm thinking--isn't there way have default mapping of urls /:module/:controller/:action ?
thanks assistance. i'm going off of zend framework 2 quick start, walked me through creating new module , adding controller module. when tried add second controller module, tripping on routing.
update: didn't catch first time through, apparently supposed feature of zend framework skeleton app. quick start guide:
zendskeletonapplication ships “default route” action. route expects “/{module}/{controller}/{action}”, allows specify this: “/zend-user/hello/world”
that's want! can't work.
it lists incomplete module.config.php, comment @ bottom putting "other configuration" here. tried figure out "other configuration" is, , wound this:
return array( 'svc' => array( 'type' => 'literal', 'options' => array( 'route' => '/svc', 'defaults' => array( 'controller' => 'svc\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( ), ), ), ), ), 'controllers' => array( 'invokables' => array( 'svc\controller\clients' => 'svc\controller\clientscontroller', ), ), 'view_manager' => array( 'template_path_stack' => array( 'album' => __dir__ . '/../view', ), ), );
jfyi, here controller looks like.
namespace svc\controller; use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel; class clientscontroller extends abstractactioncontroller { public function indexaction() { return new viewmodel(); } public function anotheraction(){ return new viewmodel(); } }
my routes not working. "route not found" when try pull of routes.
it lists incomplete module.config.php, comment @ bottom putting "other configuration" here. tried figure out "other configuration" is, , wound this:
if module.config.php looks won't work, routes
array of routes defined in router
key, config contains no such spec, try replacing this
return array( // routes 'router' => array( 'routes' => array( 'svc' => array( 'type' => 'literal', 'options' => array( 'route' => '/svc', 'defaults' => array( 'controller' => 'svc\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( // add default namespace :controllers in route '__namespace__' => 'svc\controller', ), ), ), ), ), ), ), 'controllers' => array( 'invokables' => array( 'svc\controller\clients' => 'svc\controller\clientscontroller', ), ), 'view_manager' => array( 'template_path_stack' => array( 'album' => __dir__ . '/../view', ), ), );
Comments
Post a Comment