命名规则

Classes

类名使用MixedCase并且没有下划线,每一个单词首字母大写, e.g. InvoiceItem

数据库表

表名全是小写单词之间用下划线连接,而且所有的表名都是复数的,e.g. invoice_items, orders

Model

model的命名用的是unbroken MixedCase的命名规则,并且一直都是表名的单数形式。e.g. table name might be orders, model的名字应该是Order。 Akelos将会在/app/models目录下order.php 中找寻这个类的定义。如果model的名字是复合大写的单词,那么表名被设定为单词之间有下划线的形式。

主键

一个表的主键被设定“id”。

外键

外键的命名是用目标表的名字追加_id的单数形式,e.g. order_id 这个表中的数据项中有连接到orders table的数据项。

表之间多对多的连接

表之间经常使用many to many的关系来连接两个表,命名的时候就用表名连接起来,而且要按照字母的顺序来,eg. items_orders.

自动记录活动时间特征

你可以得到活动记录来自动的更新数据库表中的创建时间和记录时间。 为了实现他们,在你的表中建立两个特殊的字段created_at和updated_at。如果你只想保存date而不是date和time,使用 created_on和updated_on.

Controller

Controller类的类名在可用的前提下是复数的,像这个OrdersController就是orders表的controller class。 Akelosorders将在/app/controllers的controller.php文件中找寻类的定义。

Action Controller and Helper Methods

Action Controller and Helper methods的命名是所有的单词都是小写,并且单词之间用下划线分开。e.g. list_all, textilize

Files, Directories and other pluralization

文件的命名是小写字母和下划线。假设我们有一个Orders controller然后下面的规则将会解释:

  • 在app/helpers目录下有一个orders_helper.php文件中 helper module名字为OrdersHelper。
  • Akelos会寻找app/views/orders的目录下Orders controller的view template文件。
  • 从这个view中可以看到输出结果然后使用app/views/layouts目录下的orders.php文件中定义的布局。
 
naming-conventions_cn.txt · Last modified: 2008/07/09 11:30 by liyh
 

The Akelos Framework was created by Bermi Ferrer and other contributors.
Potions of the code and documentation have been ported from Ruby on Rails.

The Akelos Framework is released under the LGPL license.

"Akelos", "Akelos Framework", and the Akelos logo are trademarks of Bermi Labs All rights reserved.

Wiki driven by DokuWiki