CakePHP docs
| Id/Actions | Category | Code Examples | Links | Remarks |
|---|---|---|---|---|
| 1 View |
cli commands | cake bake [project-name] cd project-name cake bake all |
||
| 2 View |
A menu item for CakePHP? | |||
| 5 View |
Naming Conventions - Controller | => controller name must match to a database table name; => If you decide to create controllers with names other than tables of the database, you should actually not create a controller but use a component instead. => The names of database tables as well as controllers are lowercase and in plural form. => example: orders table will have a controller php file name orders_controller.php under app/controllers folder. The controller class will follow OrdersController convention (CamelCased). |
||
| 6 View |
Naming Conventions - Model | => for orders table, the model file name under app/models directory would be orders.php. The class name would be Order extends AppModel. |
||
| 7 View |
Naming Conventions - View | => The view name will be the same as actions defined in controller. Suppose that there is an action called add (function add()), then there will be a view called add under app/views/<controller>/add.ctp. |
||
| 8 View |
Naming Conventions - table name with more than one word | => For example, table name is special_orders; => then the controller file should be special_orders_controller.php under app/controllers folder; => the controller class name should be SpecialOrdersController app/controllers/special_orders_controller.php file; => the model file name should be special_order.php under app/models folder. The model class should be SpecialOrder in app/models/special_order.php file. => The view name should be the same name as an action defined in its controller under app/views/<controller_name> folder. |
||
| 9 View |
Naming Conventions - Abstraction - components | If more than one controller needed to use the same actions, then you could create a component. The controllers could essentially run an include of the component and run the actions as if they were individually contained in the controller. |
||
| 10 View |
Naming Conventions - Abstraction - elements | A view to be used by multiple views is stored in what is called an element. |
||
| 11 View |
Components | Component files contain actions or functions that can be used
across all the controllers. A component typically aims to provide
tools to accomplish a main objective.
=> The file name of a component can be anything, but like
models, views, and controllers, more than one word in the
name must be separated by underscores and camel case when
naming the class object.
Including Components in the Controller with the $components Array
var $components = array('Session','RequestHandler');
Running a Component Function in the Controller
$user = $this->Session->read('User');
Components are not intended to work directly with the database, so
the component does not do much more than return a variable, a
string, or an array for the controller to use. |
||
| 12 View |
Helpers | Helpers provide functionality that is used across multiple views.
Because helpers are set apart for use in the views, they are stored
in the app/views/helpers directory.
=> example of html link helper:
<?php echo $html->link('Read Post 55','/posts/view/55');?>
=> Radio button helper ($data is an array):
<?php echo $form->radio('data');?>
|
||
| 13 View |
Elements | An element contains presentation output that can be pulled into multiple view files. => Elements are named like controller actions and view files and are stored in the app/views/elements directory. => Helpers and elements differ in that helpers work with view logic, whereas elements are more like chunks of HTML that repeat throughout the views. |
||
| 14 View |
Layouts | => a layout file to be used by the entire application or one controller action at a time. => Layouts are stored in the app/views/layouts directory and contain presentation output like views and elements. They perform minimal logic and mainly serve to wrap HTML around changing views. =>A layout's file name can be anything but must be lowercase and have the .ctp extension. |
||
| 15 View |
Behaviors | => When interacting with the database, sometimes the model will
need to perform more complex processes than simply CRUD
functionality. In some applications, deleting a record will require
performing other manipulations to other tables and records,
and so on, with other database operations. Cake resolves this issue
with behaviors, which are classes that may be called by models when
performing model functions.
=> Behaviors are stored in the app/models/behaviors directory and
can be named anything following the same rules for naming helper
files and components. They must have the .php extension.
=> In the file, behavior class names are set with the following
syntax:
class SpecialBehavior extends ModelBehavior {}
=> By using behaviors to store complex or customized model
operations, you give the application's models more consistency. |
||
| 16 View |
DataSource | DataSources are the files that execute functions that talk with a source
that stores or supplies data to the application, such as MySql,
PostgreSql, Oracle, DB2, MS Sql Server.
The DataSource abstracts the sending, retrieving, saving, and
deleting data to the model so that the model really behaves the same
regardless of what external source processes the data.
=> When creating custom DataSource, make sure the file name is
lowercase and has _source.php appended. An XML DataSource could
be named, for example, xml_source.php and would be placed in the
app/models/datasources directory. Naming the class object in the
DataSource file (in this case, for the XML DataSource) is done with
the following syntax:
class XmlSource extends DataSource {} |
||
| 17 View |
Naming Conventions - Do not conflict with PHP predefined function names | Be Careful Using PHP Function Names as Action Names, such as date(). |
Page 1 of 6, showing 15 records out of 79 total, starting on record 1, ending on 15
