CakePHP使用没有复数形式的单词命名约定

时间:2016-01-19 23:07:34

标签: cakephp cakephp-2.3

关于cakePHP和命名约定似乎有很多问题。虽然文档非常精彩,但我觉得它可以更加精确和完整。

我具体有两个问题: 1)当一个单词没有复数形式时,最佳做法是什么?就我而言,staff这个词让我感到头痛。 下面你可以找到我目前的理解,因为它与第二个模型#34; kid"有关。 2)什么是不使用HABTAM时的命名约定,而是在连接模型的每一侧使用$ hasMany和$ belongsTo。


                                                         Joining With "Kid"
Word in  | American English | Database | Model  | Controller       | Joining Table    | Joining Model | JoiningController
question | Plural form      | table    | Name   | Name             | Name             | Name
=========+==================+==========+========+==================+==================+===============+===================
Person   | People           | people   | Person | PeopleController | kids_people      | KidPerson     | KidsPeopleController
Duck     | Ducks            | ducks    | Ducks  | DucksController  | ducks_kids       | DuckKid       | DucksKidsController
Staff    | Staff            | staff    | Staff  | StaffController  | staff_kids       | StaffKid      | StaffKidsController <-- ReQ2: Is this correct? ReQ1: My interpretation of documentation.
.               ^                  ^                   ^                  ^
Staff    | Staffs           | staffs   | Staff  | StaffsController | staffs_kids      | StaffKid      | StaffKidsController <-- ReQ1: Seems to want.
Duck     | Ducks            | ducks    | Ducks  | DucksController  | duck_kids       | DuckKid       | DuckKidsController <-- ReQ2: Seems to want.

1 个答案:

答案 0 :(得分:2)

  1. 始终使用Inflector::pluraize('staff')方法测试相应的复数。这是cake用于命名约定的类。我的尝试给了我员工
  2. 连接表的命名约定始终采用 plural_plural 的形式,并且必须始终按字母顺序排列。这意味着: kids_staffs ducks_kids 等等。奇异总是复数。