Legacy Application Skeleton
pieceofcake2/app-legacy is the application skeleton for CakePHP 2 applications whose classes are global and whose templates are .ctp files, as in the original CakePHP 2. It has the same directory layout as pieceofcake2/app, compatible with CakePHP 5 (config/, src/, templates/, tests/, webroot/), the same configuration and .env files, and the same home page, layouts, error pages and styles. Only the form of the code differs:
| pieceofcake2/app-legacy | pieceofcake2/app | |
|---|---|---|
| Application classes | global (AppController) | in the App namespace (App\Controller\AppController) |
Autoloading of src/ | classmap: run composer dump-autoload after you add a class file | PSR-4 (App\ from src/, App\Test\ from tests/) |
| Templates | .ctp files in Layouts/, Elements/, Emails/ and Errors/ | .php files in layout/, element/, email/ and Error/ |
| Coding standard | CakePHP2 | CakePHP2Namespace |
Use this skeleton when your code should look like the code of an existing CakePHP 2 application, for example to move the application into the skeleton step by step. You can move the classes into a namespace later (see Moving to Namespaced Classes).
WARNING
CakePHP 2.x is for the maintenance of existing applications. For new projects, use the current major version of CakePHP instead.
Installation
Create a new application with Composer's create-project command:
composer create-project pieceofcake2/app-legacy my_appThe requirements, the installed packages and the configuration steps are the same as for pieceofcake2/app; see Requirements and Installation. In short: copy config/database.php.default to config/database.php and set DATABASE_URL in config/.env.local (and the test database in config/.env.test.local), and change the security salts (see Generating the Security Salts).
The Bake and DebugKit plugins are development dependencies. config/bootstrap.php loads them when they are installed, so bin/cake bake works out of the box and composer install --no-dev still works in production. To show the DebugKit toolbar, add the component in your AppController as described in Development Plugins, without the namespace line.
Directory Layout
my_app/
├── bin/
│ └── cake the console
├── config/ configuration (core.php, bootstrap.php, routes.php, database.php, ...)
├── logs/ log files
├── plugins/ plugins installed by Composer
├── resources/
│ └── locales/ translation files
├── src/ PHP code
│ ├── Console/ shells, tasks and bake templates
│ ├── Controller/
│ ├── Lib/
│ ├── Model/
│ └── View/ helpers
├── templates/ view templates (.ctp)
│ ├── Elements/ elements (Flash/ for the flash messages)
│ ├── Emails/ email templates (html/, text/)
│ ├── Errors/ error pages
│ ├── Layouts/ layouts (Emails/ for the email layouts)
│ └── Pages/ pages of PagesController
├── tests/
│ ├── Fixture/
│ └── TestCase/
├── tmp/ cache, sessions and test files
├── vendor/ Composer packages, including CakePHP
└── webroot/ document root (index.php, test.php, css/, js/, img/)See Directory Layout for how CakePHP finds the directories, and CakePHP Folder Structure.
Classes and Autoloading
The classes of src/ are global, and Composer loads them with a classmap:
"autoload": {
"classmap": ["src/"]
}The classmap finds a class in any folder of src/, but only after composer dump-autoload: run it every time you add a class file. The classes of CakePHP are imported with use statements, as in pieceofcake2/app:
// src/Controller/AppController.php
use Cake\Controller\Controller;
class AppController extends Controller
{
}See Autoloading.
Templates
The templates are .ctp files with the directory names of CakePHP 2:
templates/Layouts/default.ctp: the top navigation bar and the content container. Whiledebugis 2, the SQL log is shown below the content.templates/Layouts/error.ctp: a minimal layout for the error pages in production.templates/Layouts/flash.ctp: the page rendered byController::flash().templates/Elements/Flash/:default,success,error,warningandinfoflash messages.templates/Pages/home.ctp: the home page, shown at/whiledebugis enabled. Replace it with your own page before turningdebugoff.templates/Errors/error400.ctpanderror500.ctp: the error pages.
They look the same as the templates of pieceofcake2/app; see Pages and Styles for the stylesheets and the screenshots of the error pages and the flash messages.

To use the new look in an application created from an earlier version of the skeleton, copy templates/Layouts/, templates/Elements/Flash/, templates/Errors/, webroot/css/, webroot/font/ and webroot/img/cake.logo.svg into your application.
Configuration and Development
Everything else is the same as in pieceofcake2/app:
- Configuration and Environment Variables (.env)
- Database and Mailer DSNs
- Running the Application
- Running Tests and End-to-End Tests. The test cases in
tests/TestCase/and the fixtures intests/Fixture/are global classes. - Static Analysis
vendor/bin/phpcs checks the code against the CakePHP2 standard of pieceofcake2/phpcs-cakephp2 (see A phpcs.xml for Your Application).
Moving to Namespaced Classes
To move an application created from this skeleton to the form of pieceofcake2/app, run the layout and namespace commands of pieceofcake2/upgrade. In an application that already has the modern layout, layout renames the templates to .php files in the directories of CakePHP 5, and namespace moves the classes into the App namespace. See Migrating to the Modern Layout.
Origin
This package is based on the app/ directory of cakephp/cakephp (cakephp/cakephp on Packagist, last upstream version 2.10.24), originally by the CakePHP community (Cake Software Foundation, Inc.). It was extracted into a separate package and is maintained for CakePHP 2 on modern PHP by pieceofcake2. Changes from the original are listed in the commit history.
