New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于路由映射与代码组织的矛盾 #4
Comments
controller确实应该放在不同的文件夹,至于你说的处理的资源一样,那就是操作相同的model嘛!这有什么难以理解的? |
如果是MVC模式的话,这样处理是没问题的,但是以phprs的规则来看,似乎并没有对嵌套资源的情况有优化。 |
如果要套用MVC模式,可以考虑将users和catalogs当做Controller,Devices当做model。 可以定义一个如Devices类: /** @path("/")*/
class Devices{
/**@route({"GET","/users/\*/devices"})*/
public function getUserDevices....
/** @route({"GET","/catalogs/\*/Devices"})*/
public function geCatalogDevices....
} 同时Users和Catalogs中其他方法的路由不变。phprs的路由是以方法为单位,而不是以类为单位的,路由搜索时优先匹配精度高的规则。 举例来说,如果存在Devices和Users两个类,分别定义了/users//devices和/users//info接口,那么/users/id/devices会命中Devices中的方法,/users/id/info会命中Users中的方法 |
作为轻量级的解决方案, 显然 @caoym 方案要好一些,但还是有一些问题。 |
假设有两个API
按照 phprs 的规则,应该放在不同的文件中,如 users.php, catalogs.php
但是两个api处理的资源都是Device, 似乎又应该放在一个文件中。
实践上怎么处理比较好?
The text was updated successfully, but these errors were encountered: