承接 pieceofcake2/app 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pieceofcake2/app

Composer 安装命令:

composer create-project pieceofcake2/app

包简介

CakePHP 2 Application skeleton

README 文档

README

GitHub License Packagist Version PHP CakePHP

A reference implementation for CakePHP 2.x applications using a modern, CakePHP 5.x-compatible directory structure.

Warning

CakePHP 2.x is for legacy maintenance only. For new projects, use CakePHP 5.x instead.

Planning to migrate to CakePHP 5.x?

If you're planning to upgrade to CakePHP 5.x in the future, you can prepare now by adopting the modern directory structure while still on CakePHP 2.x:

Traditional migration approach (harder):

CakePHP 2.x → CakePHP 5.x
(change everything at once: code + folder structure + APIs)

New gradual migration approach (easier):

Step 1: CakePHP 2.x with traditional structure
        ↓ (modernize folder structure only)
Step 2: CakePHP 2.x with CakePHP 5.x-style structure ← You can stop here
        ↓ (upgrade code only)
Step 3: CakePHP 5.x with CakePHP 5.x-style structure

Benefits:

  • Smaller, manageable changes: Separate folder restructuring from code changes
  • Test incrementally: Verify each step works before moving to the next
  • Reduced risk: You can stay on Step 2 indefinitely if needed
  • Team-friendly: Easier for teams to understand and review smaller changes

Restructuring to Modern Layout (Step 2)

This skeleton shows you how to achieve Step 2 - running CakePHP 2.x with a modern folder structure.

Directory Structure Comparison

Before: Traditional CakePHP 2.x

your-project/
├── app/
│   ├── Config/          (uppercase, nested)
│   ├── Controller/
│   ├── Model/
│   ├── View/           (templates + helpers mixed)
│   ├── Test/
│   ├── Plugin/
│   ├── Vendor/
│   └── tmp/
│       └── logs/
├── vendors/
└── ...

After: Modern Structure (CakePHP 5.x Ready)

your-project/
├── bin/
│   └── cake
├── config/             (lowercase, top-level)
├── src/                (all PHP code)
│   ├── Controller/
│   ├── Model/
│   └── View/           (Helper classes only)
├── templates/          (all .ctp files, separated)
├── resources/
│   └── locales/
├── tests/              (lowercase, top-level)
├── plugins/            (Composer-managed)
├── vendor/             (standard Composer)
├── logs/               (separated from tmp/)
├── tmp/
└── webroot/

File Migration Map

Use this table to migrate your files from traditional structure to modern structure:

From (Traditional) To (Modern)
app/Config/* config/*
app/Controller/* src/Controller/*
app/Model/* src/Model/*
app/View/**/*.ctp templates/**/*.ctp
app/View/Helper/* src/View/Helper/*
app/Console/* src/Console/*
app/Console/cake bin/cake
app/Lib/* src/Lib/*
app/Locale/* resources/locales/*
app/Test/* tests/*
app/Plugin/* plugins/* (use Composer)
app/Vendor/* vendor/* (use Composer)
app/tmp/logs/* logs/*
app/tmp/* tmp/*
app/webroot/* webroot/*

Migration Steps

1. Update composer.json

{
    "require": {
        "php": ">=8.0",
        "pieceofcake2/cakephp": "^2.12"
    },
    "autoload": {
        "classmap": ["src/"]
    },
    "config": {
        "vendor-dir": "vendor/",
        "sort-packages": true,
        "allow-plugins": {
            "composer/installers": true
        }
    },
    "extra": {
        "installer-paths": {
            "plugins/{$name}/": ["type:cakephp-plugin"]
        }
    }
}

2. Update Bootstrap Path Definitions

Copy or reference this skeleton's webroot/index.php, webroot/test.php, and bin/cake to update the path definitions in your project:

define('ROOT', dirname(__DIR__));
define('APP_DIR', 'src');                     // Changed from 'app'
define('APP', ROOT . DS . APP_DIR . DS);
define('CONFIG', ROOT . DS . 'config' . DS);  // Top-level, lowercase
define('TESTS', ROOT . DS . 'tests' . DS);    // Top-level, lowercase
define('TMP', ROOT . DS . 'tmp' . DS);        // Top-level
define('LOGS', ROOT . DS . 'logs' . DS);      // Separated from tmp/
define('VENDORS', ROOT . DS . 'vendor' . DS); // Standard Composer

Refer to this skeleton's implementation files for complete examples.

3. Migrate Files

Move files according to the File Migration Map above. You can do this gradually:

  1. Configuration files: app/Config/*config/*
  2. PHP code: app/Controller/*, app/Model/*src/
  3. Templates: app/View/**/*.ctptemplates/
  4. Tests: app/Test/*tests/
  5. Dependencies: Use Composer for plugins and vendors

4. Verify Your Application Still Works

The pieceofcake2/cakephp core automatically supports this modern structure with App::uses() and class loading, so your existing CakePHP 2.x code should work without modifications.

5. Leverage Composer Autoloading (Optional)

Once Composer's autoload is configured in composer.json, you can remove App::uses() calls from your code:

"autoload": {
    "classmap": ["src/"]
}

After running composer dump-autoload, you can safely remove App::uses() statements from your controllers, models, helpers, and shells.

Important

You must run composer dump-autoload every time you create a new class file. Composer's classmap autoloader needs to be regenerated to recognize new classes.

For example:

// Before
App::uses('AppController', 'Controller');

class UsersController extends AppController {
    // ...
}

// After (with Composer autoload)
class UsersController extends AppController {
    // ...
}

Note: Plugins that don't support Composer autoloading will still require App::uses() or CakePlugin::load() to function properly.

Upgrading to CakePHP 5.x (Step 3)

Once you've completed Step 2 (modern folder structure with CakePHP 2.x), upgrading to CakePHP 5.x becomes much simpler:

What's already done:

  • ✅ Directory structure is already correct - No need to reorganize files
  • ✅ Templates already separated - No need to move .ctp files
  • ✅ Modern Composer setup - Already using vendor/ and plugins/

What you need to do:

  • Update composer.json to require CakePHP 5.x
  • Update code for CakePHP 5.x API changes
  • Test and fix compatibility issues

The key advantage: You can focus 100% on code changes, not structural changes.

Refer to the CakePHP 5.x Migration Guide for framework-specific changes.

Requirements

  • PHP 8.0, 8.1, 8.2, 8.3, 8.4, 8.5
  • Composer
  • Database: MySQL 5.6+, PostgreSQL 9.4+, SQLite 3, or SQL Server 2022+
  • PHP Extensions: mbstring, intl, openssl, PDO driver for your database

See pieceofcake2/cakephp requirements for details.

Technical Implementation

This modern directory structure works with CakePHP 2.x through custom path configuration in bootstrap files (webroot/index.php, webroot/test.php, bin/cake).

The pieceofcake2/cakephp core has been enhanced to:

  • Automatically load classes from src/Controller/, src/Model/, etc. with App::uses()
  • Find templates in the templates/ directory
  • Support both modern and traditional file locations during migration

You don't need to modify your application code - the framework handles the path mapping automatically.

Development

Running Tests

./bin/cake test app AllTests

Or with PHPUnit:

./vendor/bin/phpunit

Code Standards

Check your code against CakePHP coding standards:

./vendor/bin/phpcs

Documentation

License

MIT License. See LICENSE file for details.

Support

This is a community-maintained fork of CakePHP 2.x. For issues and questions:

pieceofcake2/app 适用场景与选型建议

pieceofcake2/app 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.33k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cakephp」 「Skeleton」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pieceofcake2/app 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pieceofcake2/app 我们能提供哪些服务?
定制开发 / 二次开发

基于 pieceofcake2/app 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 21
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-05