誰かがMVCでのアクションに適した命名規則を確立しましたか?私は特にASP.netMVCを見ていましたが、それは一般的な質問です。たとえば、ログイン画面を表示するアクション(Login)と、そのページからのログイン要求を処理するアクション(LoginTest)があります。私は名前に熱心ではなく、書くべきアプリケーションがたくさん残っています。
6 に答える
MS の Rob Conery は、アクションの便利な RESTful スタイルの命名を提案しました。
* Index - the main "landing" page. This is also the default endpoint. * List - a list of whatever "thing" you're showing them - like a list of Products. * Show - a particular item of whatever "thing" you're showing them (like a Product) * Edit - an edit page for the "thing" * New - a create page for the "thing" * Create - creates a new "thing" (and saves it if you're using a DB) * Update - updates the "thing" * Delete - deletes the "thing"
(フォーラムの場合) の行に沿った URL になります。
* http://mysite/forum/group/list - shows all the groups in my forum * http://mysite/forum/forums/show/1 - shows all the topics in forum id=1 * http://mysite/forums/topic/show/20 - shows all the posts for topic id=20
Rails には CRUD 操作のための優れたアクション命名規則があります: Rails Routing from the Outside Inです。
HTTP Verb Path Controller#Action Used for
GET /photos photos#index display a list of all photos
GET /photos/new photos#new return an HTML form for creating a new photo
POST /photos photos#create create a new photo
GET /photos/:id photos#show display a specific photo
GET /photos/:id/edit photos#edit return an HTML form for editing a photo
PATCH/PUT /photos/:id photos#update update a specific photo
DELETE /photos/:id photos#destroy delete a specific photo
これは基本的に、Paul Shannon の answer の更新です。彼の情報源 (Rob Conery) は、Rails からリストをコピーしたと暗に述べているからです。
ASP.NET MVC のヒント #11に関する Stephen Walther の投稿– 標準コントローラー アクション名を使用すると、おそらく命名規則の命名規則について明確になるでしょうMVC Action...
Stephen Waltherによるブログ投稿が、一貫した命名スキームを見つけるのに役立つことを発見しました。彼が説明するいくつかのユニークな例外を除いて、REST スタイルの命名スキームから派生したものでもあります。
組み込みのDjangoアクションサフィックス_done。したがって、LoginDoneは、ログインを処理するページになります(ASP.NET MVCキャメルケーススタイル)。
コントローラ アクションの命名にどの規則を使用するかは、それが一貫しており、それに取り組んでいる人が簡単に理解できる限り、まったく関係ありません。
ログイン アクションの場合、LoginDone は問題なく、ProcessLogin は理解しやすいので、使い慣れた規則を使用してください。
個人的には、LoginDone はおそらく Action が行っていることに関して少し誤解を招く可能性があるため、Login と ProcessLogin の側に立つでしょう。ログインが成功したら LoginDone という別の Action にパススルーできます。失敗した場合は LoginFailed にパススルーできます。