dounianluo0086 2013-07-18 07: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 08: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部