2015-04-27 24 views
0

在CakePHP 3中,其餘路由不調用子名稱空間中的類。例如,路線「posts/2/comments/10」調用App \ Controller \ CommentsController。我想它來調用應用程序\控制器\文章\ CommentsController因爲意見不總是對的帖子...CakePHP3中的嵌套REST路由和子名稱空間

這裏是我的解決方案:

$routes->resources('Posts'); 
Router::scope('/posts/:post_id/',['post_id'=>'[0-9]+','prefix'=>'posts'], function($routes){ 
    $routes->resources('Comments'); 
});  

它工作正常,但我不知道這是否是一個好的做法。

謝謝

回答

0

如果通過命名空間使用Router::prefix()$routes->prefix()代替$routes->scope()

想組控制器