downloadTemp2014 2011-06-21 15:29
浏览 87

Yii中的RESTful服务器设计

Hi i have been trawling the net in search of as much info i could get my mits on about creating a restful server in the Yii framework.

All the examples i have found so far have dealt with writing a restful application that deals with one model (IE Topic Or Posts)

The crux of my question is this, How should i deal with writing a restful server that deals with alot of Model types, ie client, brand, project, task?

Each Model object will need CRUD operations to be implemented so for example To create a new brand the system requires a Client Id as will the other CRUD operations.

Should each Model Object have its own RESTFUl server or should there be come kind of controller that routes the RESTFUL requests to the corresponding Rest controller for the model object? Should there be one Server that dynamically decides what model to work with like a switch (not keen on this idea personally)

Any kind of advice of how to achieve this kind of rest architecture would be really great

I think its also worth noting that the server i am building will be working with sproutcore on the front end and will only be returning JSON so any kind of format detection will not be required.

  • 写回答

3条回答 默认 最新

  • dqxuiq7772 2011-06-22 20:24
    关注

    Run through this tutorial. Just duplicate the controller actions. Edit the second set of actions to interact with a new model. For example, the tutorial calls for the following actions to be created in the controller:

    public function actionList()
    {
    }
    public function actionView()
    {
    }
    public function actionCreate()
    {
    }
    public function actionUpdate()
    {
    }
    public function actionDelete()
    {
    }
    

    You would create alternate actions for your second model. Something like:

    public function actionListB()
    {
    }
    public function actionViewB()
    {
    }
    public function actionCreateB()
    {
    }
    public function actionUpdateB()
    {
    }
    public function actionDeleteB()
    {
    }
    

    If you need more information or clarification please leave a comment. Good luck.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起