SailsJS从控制器访问服务

我试图在sailsjs中创build一个服务,所以我可以从多个控制器访问一些业务逻辑,我偶然发现了一些问题…该服务是一个'行动日志'我希望logging有关特定API调用的数据通过模型到数据库。

我有这个文件结构:

api/services/actionService.js - the service to receive data from controller and log to model api/models/Action.js - functioning model to store logged actions api/controllers/ActionController.js - functioning controller to respond to get requests for the action model api/controllers/AnotherController.js - I wish to access the actionService from here to input data 
  1. 我不确定如何引用AnotherController.js的服务; 根据帆的文档,我应该可以调用ActionService(data)但我得到一个ActionService is not defined错误。 有什么我需要做的加载控制器的这种依赖关系?

  2. 我能够从服务中引用模型吗? 此刻我有一些像Action.create(action)...在服务中。 这还没有引起问题,因为我还没有通过第一个问题,但想知道我是否也需要加载这个作为服务的依赖?

我是新手,在sailsjs中实现服务,任何帮助表示赞赏。

您可以使用以下语法在任何控制器中访问您的服务:

<yourServicefilename>.method();

在你的情况下,它将是actionService.<yourMethodName>()