Router, Annotations and addResource

Is it me, do I do something wrong or is it a bug?

With this gist — https://gist.github.com/suxxes/44eea5e6f347337dd72c I get a structure like this:

public/index.php app/controllers/AnyThingController.php app/controllers/SomeThingController.php

Well, there obviously is a router.php, which is nothing, but the router file for PHP built-in WebServer, so we will not consider it.

The thing is, that when I visit /any/thing, I get: string(31) "AnyThingController::indexAction" Looks OK isn't it?

However when I visit /some/thing, I get: string(32) "SomeThingController::indexAction" string(48) "Cannot obtain a route using the name "any-thing""

Which leads me to the thought, that annotations are being read only on used files, or am I wrong?

My Phalcon version is 0.9.0 and I'm running PHP 5.4.12 on Mac OS X 10.7

I test this situation on Phalcon 1.0.0 Beta and everything is ok.



1.1k

Thanks. Seems to be a bug-or-feature. To make it work on 0.9.0 you should remove $prefix argument for Router->addResource.

Otherwise you will have the error I had.



84.1k

The controllers are only read if the current URI matches the prefix which the resource was registered, this saves the process of read every controller in every request which is not fine because it impacts performance. So the router does not know about the routes if the controller has not been read in the request.

$router->addResource('SomeThing');
$router->addResource('AnyThing');

So, you can register your resources without prefixes but this will lead to increase the number of files read and parsed in every request.