简体   繁体   English

如何在Phalcon API Rest中设置大量资源?

[英]How to set multple resources in phalcon api rest?

i just followed this docs api rest phalcon and it worked!, but i don't know how to properly set more resources like robots in the example, if i have 10 resources i don't like to have them in the same file. 我只是遵循了这个文档api rest phalcon ,它起作用了!但是我不知道如何在示例中正确设置更多的资源,例如机器人,如果我有10个资源,我不希望它们在同一个文件中。

using router? 使用路由器?

Thanks a lot. 非常感谢。

If by resources you mean models and if it works as is, you can simply create more models in my-rest-api/models/ directory. 如果按资源表示模型,并且按原样运行,则只需在my-rest-api/models/目录中创建更多模型。 Normally you'd need to configure an autoloader, but micro apps probably know where to get models from. 通常,您需要配置自动加载器,但是微型应用程序可能知道从何处获取模型。

If you are asking how to make your app better organised you probably need to move away from the micro app and take advantage of the MVC pattern. 如果您要问如何使您的应用程序更好地组织起来,那么您可能需要远离微型应用程序并利用MVC模式。 If in the example you worked with a single model and all related logic was handled in a single file, with MVC all logic is organised into controllers. 如果在示例中您使用的是单个模型,并且所有相关逻辑都在单个文件中处理,那么在MVC中,所有逻辑都组织在控制器中。 Normally single controller handles logic related to a single model or models related to it. 通常,单个控制器处理与单个模型相关的逻辑。 The official tutorial explores this in depth with further references. 官方教程将对此进行深入探讨,并提供更多参考。

Edit: 编辑:

And as Julian himself pointed out Phalcon\\Mvc\\Micro\\Collection is another approach for micro apps. 正如朱利安本人指出的那样, Phalcon\\Mvc\\Micro\\Collection是用于微型应用程序的另一种方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM