Contents
CakePHP
A convention-based framework: a powerful ORM, the bake code generator, forms and validation out of the box.
1.Getting started
- Introduction to CakePHPWhat CakePHP is, how to create a project, run it, and what its folders contain.
- Naming conventionsHow to name tables, classes, files and columns so that CakePHP connects them by itself.
- The console and bakeThe bin/cake command: running the server, listing commands and generating code with bake.
- RoutingThe config/routes.php file: how to connect an address to a controller, pass a parameter, name a route and build a link.
- ControllersWhat a controller and an action are, where controllers live, how to create them and pass data to a template with set.
- Request and responseHow to read address parameters and form fields, redirect a visitor and return JSON from a controller action.
- TemplatesThe templates folder: how to name a template file, output variables from a controller and escape them with h.
- Layouts, elements and helpersThe common page frame in templates/layout, reusable fragments in templates/element and the Html and Url helpers for links.
- ConfigurationThe config/app.php, app_local.php and .env files: where to keep settings, how to read them with Configure and add your own.
2.Database
- Connecting to the databaseHow to create a database, write the connection settings to config/app_local.php and check that CakePHP sees it.
- MigrationsHow to describe a database table in code, create it with a command and change the structure with a new migration.
- SeedsSeeds in config/Seeds: how to fill a table with initial or test records with one command.
- Tables and entitiesThe basis of the CakePHP ORM: table and entity classes in src/Model, creating them with bake model and first use in a controller.
- Finding dataORM queries: find, where, orderBy, limit, first, get and count, or how to get the records you need from a table.
- Saving and deletingHow to create a record with newEmptyEntity, fill it with patchEntity, save, change and delete it.
- AssociationsThe belongsTo, hasMany and belongsToMany associations in the table class and loading related records with contain.
3.Application
- ValidationValidation rules in validationDefault and application rules in buildRules: where to write them and how to get the errors.
- FormsThe Form helper: how to render a form for an entity, handle it in an action, show errors and make a delete button.
- Flash messages and sessionsThe Flash component for messages after an action and the session for visitor data between requests.
- PaginationThe paginate method in a controller and the Paginator helper in a template: list pages, links and sorting by columns.
- BehaviorsTable behaviors: the ready-made Timestamp, other built-in ones and a custom behavior in src/Model/Behavior.
- AuthenticationThe Authentication plugin: installation, password hashing, setup in Application.php, the login and logout actions.
- AuthorizationThe Authorization plugin: policies in src/Policy, checking permissions in an action and in a template.
- File uploadsHow to accept a file from a form, check it, save it to webroot/uploads and show it on a page.
4.Growing the project
- REST APIAn API in CakePHP: resources routes, JSON responses with JsonView, receiving data and status codes.
- MiddlewareWhat middleware is, where the middleware queue is in Application.php and how to write your own in src/Middleware.
- CachingThe Cache class: how to store the result of a heavy query, read it, reset it and where to configure the storage.
- Sending emailThe Mailer class: transport setup, a simple message, your own mailer class in src/Mailer and email templates.
- Custom commandsConsole commands in src/Command: creating with bake, arguments and options, output and running on a schedule.
- Logging and errorsThe Log class and the logs folder, the debug function, exceptions for 404 and 403 errors and custom error pages.
- Testing basicsTests in the tests folder: the test database, fixtures, checking pages and forms and running with PHPUnit.
- DeploymentHow to move a CakePHP project to a server: the webroot document root, production mode, folder permissions and update commands.