Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
23 Cards in this Set
- Front
- Back
Filenames
|
Filenames are underscored. Eg. my_nifty_class.php
|
|
Classnames
|
Classnames are CamelCased. Eg. MyNiftyClass
|
|
Controller classname/filename
|
The Controller class KissesAndHugsController would be found in a file named kisses_and_hugs_controller.php (notice _controller in the filename)
|
|
Component classname/filename
|
The Component class MyHandyComponent would be found in a file named my_handy.php
|
|
Model classname/filename
|
The Model class OptionValue would be found in a file named option_value.php
|
|
Behavior classname/filename
|
The Behavior class EspeciallyFunkableBehavior would be found in a file named especially_funkable.php
|
|
View classname/filename
|
The View class SuperSimpleView would be found in a file named super_simple.ctp
|
|
Helper classname/filename
|
The Helper class BestEverHelper would be found in a file named best_ever.php
|
|
From Model classnames to Table names
|
Model classnames are singular and CamelCased. Person, BigPerson, and ReallyBigPerson are all examples of conventional model names.
Table names corresponding to CakePHP models are plural and underscored. The underlying tables for the above mentioned models would be people, big_people, and really_big_people, respectively. |
|
Foreign key in DB
|
A foreign key is a reference to a recordset in another table by its (Primary Key?) id.
|
|
Foreign key field name format
|
Foreign keys in hasMany, belongsTo or hasOne relationships are recognized by default as the (singular) name of the related model followed by _id. So if a baker hasMany cakes, the cakes table will refer to the baker in the bakers table via a baker_id foreign key.
|
|
hasAndBelongsToMany relationship
|
Cake allow you to relate two tables in a n<->m relation. This is done by the HasAndBelongsToMany relationship (HABTM). In order to implement this relationship you need three table: the two tables to be related and a table for the relationship.
|
|
HasAndBelongsToMany joined tables - naming
|
Model tables they will join in alphabetical order (apples_zebras rather than zebras_apples)
|
|
Primary key rules
|
All tables with which CakePHP models interact (with the exception of join tables), require a singular primary key to uniquely identify each row.
|
|
Primary key of join tables
|
CakePHP's convention is that a single-field primary key is added to the table.
|
|
Controller classnames
|
Controller classnames are plural, CamelCased, and end in Controller. PeopleController and LatestArticlesController are both examples of conventional controller names.
|
|
Controller index() function (or method)
|
The first function you write for a controller might be the index() function. When a request specifies a controller but not an action, the default CakePHP behavior is to execute the index() function of that controller.
|
|
Visibility of controller function
|
If a controller function has been prefixed with an underscore, the function will not be accessible directly from the web but is available for internal use.
While the page http://www.example.com/news/latest/ would be accessible to the user as usual, someone trying to get to the page http://www.example.com/news/_findNewArticles/ would get an error, because the function is preceded with an underscore. |
|
Accessing a controller with a URL
|
Single word controllers map easily to a simple lower case URL path. For example, ApplesController (which would be defined in the file name 'apples_controller.php') is accessed from http://example.com/apples
|
|
Inflecting(/Correcting?) the URL
|
An mistake in the inflection of the URL will still access the correct controller in these cases:
* /redApples * /RedApples * /Red_apples * /red_apples will all resolve to the index of the RedApples controller. However, the convention is that your urls are lowercase and underscored, therefore /red_apples/go_pick is the correct form to access the RedApplesController::go_pick action. |
|
Accessing a view class function
|
View template files are named after the controller functions they display, in an underscored form. The getReady() function of the PeopleController class will look for a view template in /app/views/people/get_ready.ctp
The basic pattern is /app/views/controller/underscored_function_name.ctp |
|
Relationships in conventions example
|
Here’s a final example that ties the conventions
* Database table: "people" * Model class: "Person", found at /app/models/person.php * Controller class: "PeopleController", found at /app/controllers/people_controller.php * View template, found at /app/views/people/index.ctp |
|
Controller view templates
|
A controller will call a View template, found at /app/views/***/+++.ctp where *** is the controller name and +++ is the name of the method
|