[fw-general] Re: ZF2 and understanding routes.

2012-10-15 Thread ryanrk
Yes,  that did it.  So we need to add an invokable for every controller?

Is there an easy way to make the routes default to a module so the module
name isn't in the URL?
Localhost/test instead of localhost/module/test

Thanks for your help,
Ryan



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-and-understanding-routes-tp4657579p4657583.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




[fw-general] Re: ZF2 and understanding routes.

2012-10-14 Thread luk
ryanrk wrote
> Yes,  that did it.  So we need to add an invokable for every controller?

Yes, it is one of possible options to add your Controller into invokables.
The other option would be to create your Controller with a Factory and by
using Service Manager inject needed dependencies.


ryanrk wrote
> Is there an easy way to make the routes default to a module so the module
> name isn't in the URL?
> Localhost/test instead of localhost/module/test

To achieve this just use "/" in parent route and remove first forward slash
from child route:
'application' => array(
'type'=> 'Literal',
'options' => array(
'route'=> '/', // updated here...
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller'=> 'Index',
'action'=> 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type'=> 'Segment',
'options' => array(
'route'=> '[:controller[/:action]]', // and
here
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),



-
Cheers,
--
Luke Mierzwa
--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-and-understanding-routes-tp4657579p4657585.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




[fw-general] Re: ZF2 and understanding routes.

2012-10-14 Thread luk
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