dounianluo0086 2013-07-18 15:17
浏览 58
已采纳

RESTful控制器,具有多种CRUD方法

This is something I don't understand quite well I making making an App for my self using Laravel and would like to upkeep to standards.

So I have the following:

class UserController extends BaseController {

    GET index(), show(), new(), edit()        
    POST create()
    PUT update()
    DELETE destroy()
}

class UserModel { hasMany->Assets }

class Asset { pulic function fetchAssetsFromApi(); }

Now I don't have an Asset controller because there is nothing about Asset that needs to be displayed on it's own. I simply have the model for the ORM purposes to represent assets table.

Now the Assets model has a method that pulls Assets associated with a particular User and adds them to the database.

Now my view that is rendered by UserController->show has a button called Update Assets that should call fechAssetsFromApi() to update characters assets. However since there is no way to invoke alone with a button I would have to POST to a controller.

Meaning now I would need to have another method in my UsersController since it's the only one that will be using Assets model.

Now my question is does this break rules and guidelines for RESTfull controllers ? I will have this similar dilema appear multiple time in application ho should i approach it.

Should a proper RESTFull controller contain only CRUD or ?

  • 写回答

1条回答 默认 最新

  • dongxi1879 2013-07-18 16:13
    关注

    As far as I know, having more functions in a controller is fine, but you should only have your public functions be your CRUD functions. In this case, I would just make a link that, when clicked, will just go back to the that same route. This means that the same show() function will be called, except anything that has been updated will now be pulled to the page. Essentially force a refresh of the browser page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址