Comments (4)
controller确实应该放在不同的文件夹,至于你说的处理的资源一样,那就是操作相同的model嘛!这有什么难以理解的?
from phpboot.
如果是MVC模式的话,这样处理是没问题的,但是以phprs的规则来看,似乎并没有对嵌套资源的情况有优化。
按我的理解, /users/100/Devices 和 /catalogs/200/Devices 两个路由应该放在同一个类里面,但是它们的url第一段是不一样的,因此有困惑。
from phpboot.
如果要套用MVC模式,可以考虑将users和catalogs当做Controller,Devices当做model。
当然,如果只是想把 /users/100/Devices 和 /catalogs/200/Devices 放在一个类里,也是有办法的。
可以定义一个如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中的方法
from phpboot.
作为轻量级的解决方案, 显然 @caoym 方案要好一些,但还是有一些问题。
以答复中Devices的例子, 如果path 指定为 “/”, 会导致后面每个方法的 route声明都要带 /devices
from phpboot.
Related Issues (20)
- 路由算法需要增加严格匹配模式 HOT 13
- 如何定义文件传输的接口呢? HOT 4
- Exceptions throwed by hook, can't be catched. HOT 1
- create \PDO with IoCFactory failed
- cannot extract the “0” node from url path
- how to create the database table for example/users? HOT 1
- 如何自定义配置段 HOT 1
- 求助,"error":"phprs\\util\\exceptions\\NotFound","message HOT 1
- How about add 401 unAuth error response HOT 2
- 想做一个签名校验 HOT 2
- undue sql wrap with ``
- 有版本功能吗? HOT 2
- 想问一下如何添加根据路径的hook HOT 1
- 找不到类的报错 HOT 2
- Class App\Controllers\Books does not exist HOT 1
- 请问RPC调用如何设置超时时间?
- 支持mongodb数据库吗 HOT 2
- 关于APC扩展
- How to access custom values defined in config.php
- conf.json 可能泄漏 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpboot.