Is it possible to group controllers in sails using subfolders?

前端 未结 4 1232
囚心锁ツ
囚心锁ツ 2020-12-11 06:53

I\'m planning to organize my controllers in sails using subfolder but I\'m not sure how to do it. When I tried using like admin/PageController.js and connect it with the rou

4条回答
  •  独厮守ぢ
    2020-12-11 07:01

    You can definitely do this. The trick is, the controller identity is its path, in your case admin/PageController. So a custom route in config/routes.js would be something like:

    'GET /admin/page/foo': 'admin/PageController.foo'
    

    The great thing is, automatic actions still work, so if you have an index action in the controller then browsing to /admin/page will automatically run it.

    You can also create controllers like this with sails generate controller admin/page.

提交回复
热议问题