0

I want to implement a RESTful webservice by using Zend Framework 2, more precisely 2.1.5. I got a 404 if I visit http://ehcserver.localhost/rest, the corresponding message is 'rest(resolves to invalid controller class or alias: rest)'. What went wrong?

You can see my source code in my github-repository: https://github.com/Jochen1980/EhcServer/blob/master/module/Application/config/module.config.php

The route is defined like this:

return array(
    'router' => array(
        'routes' => array(
            'rest' => array(
                'type' => 'ZendMvcRouterHttpSegment',
                'options' => array(
                'route' => '/:controller[.:formatter][/:id]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'formatter' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[a-zA-Z0-9_-]*'
                ),
            ),
         ),
         'home' => array(
         ...
2
  • Do you actually have a RestController class in your YourModule/Controller folder. If so, have you mapped it in the invokables section of the controllers array in module.config.php ? ie., 'YourModule\Controller\Rest' => 'YourModule\Controller\RestController', Commented May 3, 2013 at 14:39
  • Thanks Crisp, as you can see in my repository, I think I have done both. Any further advice? Commented May 3, 2013 at 14:59

2 Answers 2

2

Your route doesn't define a namespace to which the controller belongs, you need to add a __NAMESPACE__ to route defaults

        'rest' => array(
            'type' => 'ZendMvcRouterHttpSegment',
            'options' => array(
                'route' => '/:controller[.:formatter][/:id]',
                'defaults' => array(
                    // tell the router which namespace :controller belongs to
                    '__NAMESPACE__' => 'Application\Controller',
                ),
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'formatter' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id' => '[a-zA-Z0-9_-]*'
                ),
            ),
        ),
Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure the type is valid?

type' => 'ZendMvcRouterHttpSegment',

to this

type' => 'Segment',

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.