Lock
Lock

Reputation: 5522

Using phalcon's annotations to define multiple routes to the one controller

I am trying to use Phalcon's annotations to define my routes.

I currently have 2 different routes pointed to the same controller so that I can reuse the login:

$router->add("/delivery-methods/:action/:int", array(
  "controller" => "code",           
  "action" => 1,
  "id" => 2,
  "code_type" => "delivery-method"
));

//manage quarantines
$router->add("/quarantines/:action/:int", array(
  "controller" => "code",           
  "action" => 1,
  "id" => 2,
  "code_type" => "quarantine"
));

How can I convert this into annotations on my Code controller? I tried something like:

/**                                
 * @RoutePrefix("/delivery-methods")  
 * @RoutePrefix("/quarantines")     
 */

However the second line doesn't work. I also need a way to statically say that "when the route is delivery-method, set the code_type to delivery-method" etc.

Any ideas? Or can this simply not be done through annotations?

Upvotes: 2

Views: 263

Answers (1)

Mahdi Mohammadi
Mahdi Mohammadi

Reputation: 91

i think you should use 'namespace' in route parametrs like this

$router->add('/admin',array(
      'namespace'  => "Multiple\Admin\Controllers\\",
      'module'     => "admin",
      'controller' => 'index',
      'action'     => "index",
))->setName('adminArea');

Upvotes: 1

Related Questions