Quantcast

Controller class mapping problems...or missing dependencies...?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Controller class mapping problems...or missing dependencies...?

travis
This post has NOT been accepted by the mailing list yet.
Alright, I've stumbled on to a new problem...one of my controller class aliases doesn't seem to get any respect.

Here are the main bits of my config:
        'controller' => array(
                'classes' => array(
                        'index'       => 'Application\Controller\IndexController',
                        'events'      => 'Application\Controller\EventController',
                        'faq'         => 'Application\Controller\FaqController',
                        'about'       => 'Application\Controller\AboutController',
                        'error'       => 'Application\Controller\ErrorController',
                ),
        ),
        'router' => array(
                'routes' => array(
                        'default' => array(
                                'type' => 'Regex',
                                'options' => array(
                                        'regex' => '/.*',
                                        'defaults' => array(
                                                'controller' => 'error',
                                                'action' => 'index',
                                        ),
                                        'spec' => '404',
                                ),
                        ),
                        'home' => array(
                                'type'    => 'Literal',
                                'options' => array(
                                        'route' => '/',
                                        'defaults' => array(
                                                'controller' => 'index',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),
                        'events' => array(
                                'type'    => 'Literal',
                                'options' => array(
                                        'route' => '/events',
                                        'defaults' => array(
                                                'controller' => 'events',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),
                        'faq' => array(
                                'type'    => 'Literal',
                                'options' => array(
                                        'route' => '/faq',
                                        'defaults' => array(
                                                'controller' => 'faq',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),
                        'about' => array(
                                'type'    => 'Literal',
                                'options' => array(
                                        'route' => '/about',
                                        'defaults' => array(
                                                'controller' => 'about',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),

When I point my browser to mydomain.com/faq or mydomain.com/about, then everything works well and (it appears) that the expected controller is used as well as the expected view script.

The problem is when I point my browser to mydomain.com/events.  I get taken to my 404 page and told "The requested controller could not be mapped to an existing controller class."  The only way I can get this to work is to rewrite the events route section as follows:

                        'events' => array(
                                'type'    => 'Literal',
                                'options' => array(
                                        'route' => '/events',
                                        'defaults' => array(
                                                'controller' => 'Application\Controller\EventController',
                                                'action'     => 'index',
                                        ),
                                ),
                        ),

When I do this, then it works like a champ.

Actually, I may have found the problem, but if I'm right, then the error message is misleading.  I have some DI setters in my event controller that I haven't fully wired up yet.  When I copy/paste the same dependencies into my about controller, then I get the same 404 page with the same error message.

So, my guess is that ZF2 sees that there are dependencies and, when it can't satisfy those dependencies, it dies.

First off, I'm not sure that this is the best way to do things.  Perhaps the controller gets instantiated and used sans dependencies.  Who knows?  This may be better off in another discussion.

Secondly, though, it appears the error message should be something more along the lines of "hey, we got your controller, but we can't satisfy all of the dependencies, so we're going to die now."  Then, as the developer, I know it's (probably) a wiring problem.

Anyway, I think I've answered the first question I had, but I'm ending with something different....Should the framework behave this way in the first place?  And, shouldn't the error message provide different/better feedback?

Any thoughts/feedback from anyone out there would be welcome.

Thanks...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller class mapping problems...or missing dependencies...?

macest
This post has NOT been accepted by the mailing list yet.
Can you post your DI config.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller class mapping problems...or missing dependencies...?

travis
This post has NOT been accepted by the mailing list yet.
No need.  I found out the problem, as I talked about in the latter part of my post.  However, I also discussed why I think that the zf2 error message in such situations is misleading.

Thanks.
Loading...