The Trax Naming Convention
Trax uses naming conventions instead of explicit configuration
to link the various parts of a Trax application. From the name of
a component, Trax can compute the names of related components.
This lets you build an application faster because you need to do
less.
Conversion of names between singular and plural or between
CamelCase and lower_case_underscore forms is done by methods of the
Inflector class.
Names In the Model
Database tables have names which are
English plural words in lowercase. Where the name is two or more
words, the words are connected by underscores ('_').
Examples:
orders
people
approved_medications
The primary key column of each table is called
id
.
There is also a naming convention for foreign keys. A foreign
key which selects a row in a table by (only) the
id
column is the singular lower_case_underscore
name of that table with suffix _id
. For
example, a foreign key to the people
table's id
column would be stored
in a column named person_id
.
Column names containing the string password
are treated specially by ActiveRecordHelper.
ActiveRecord subclasses have names
which are English singular words in CamelCase. Where the name is
two or more words, the first letter of each word is capitalized.
Each table in the database has a one-to-one relationship with a
subclass of ActiveRecord whose name is the CamelCase singular of
the table name. Examples corresponding to the table names listed
above:
Order
Person
ApprovedMedication
The subclass is contained in a file in the
app/models
area of the Trax work area. The file
name is the lower_case_underscore form of the subclass name.
Examples corresponding to the subclasses listed above:
order.php
person.php
approved_medication.php
Names In the Controller
The Controller is implemented as
ApplicationController subclasses that
have descriptive names in CamelCase. The last
word of a controller name is Controller
. The
word(s) of the controller name before Controller
describe the thing controlled. For example:
StoreController
CreditAuthorizationController
Each ApplicationController subclass is contained in a file
whose name is the lower_case_underscore form of the subclass name.
This file stored in the app/controllers
area of
the Trax work area. For example, the files containing the
subclasses listed above are:
store_controller.php
credit_authorization_controller.php
Each ApplicationController subclass also has a helper file in
the app/helpers
area of the Trax work area with
a file name which is the same as the name of the controller file with
helper
substituted for
controller
. For example, the helper files for
the controllers listed above are:
store_helper.php
credit_authorization_helper.php
Names In the View
There is a view associated with each controller. The
templates for that view are stored in the
app/views
area of the Trax work area in a
directory whose name is the desciptive part of the controller
name. For example, the view template files for the controllers
listed above are stored in:
app/views/store/
app/views/credit_authorization/
The layout for each view is stored in the
app/views/layouts
area of the Trax work area in
a file whose name is the desciptive part of the controller
name with a .phtml
extension. For example, the
layouts for the controllers listed above are stored in:
app/views/layouts/store.phtml
app/views/layouts/credit_authorization.phtml
Fields On Forms
Input fields on forms that relate directly to elements of the
model are named according to the ActiveRecord subclass and
attribute represented by the field. Simple elements are given
id="
"
and
name="
[
]"
.
For example, a field to input the first name of a person which is
attribute fname
of subclass
Person
would appear as:
<input id="Person_fname name="Person[fname]" type="text" ... />
When the form is POSTed to the server, the value entered into this
field will be in $_REQUEST['Person']['fname']
Certain attributes, such as dates and times, are composites of
individual fields representing year, month, day, hour, minute and
second. Each field is named with the attribute name followed by a
suffix describing which component is represented. The suffixes
for dates and times are:
(1i)
Year
(2i)
Month
(3i)
Day of the month
(4i)
Hour
(5i)
Minute
(6i)
Second
For example, a group of three pulldown menus which specified
attribute birthdate
of subclass
Person
would be named:
Month:
<select name="Person[birthdate(2i)]"> ... </select>
Day:
<select name="Person[birthdate(3i)]"> ... </select>
Year:
<select name="Person[birthdate(1i)]"> ... </select>
When the form is POSTed to the server, the selected values will
appear in $_REQUEST['Person']['birthdate(2i)']
,
$_REQUEST['Person']['birthdate(3i)']
and
$_REQUEST['Person']['birthdate(1i)']
respectively. The value would be stored in the database in a
column of type date
and would be
represented according to the SQL standard as
YYYY-MM-DD
.