CakePHP:从 3.6.x 升级到 4.0“缺少模板异常" [英] CakePHP: upgrade from 3.6.x to 4.0 "Missing Template Exception"

查看:26
本文介绍了CakePHP:从 3.6.x 升级到 4.0“缺少模板异常"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了升级指南(在我从 3.6 升级到 3.8 之后)但我收到这个错误:

I followed the upgrade guide (after I upgraded from 3.6 to 3.8) but I get this error:

错误:[CakeViewExceptionMissingTemplateException] 模板文件Errorerror500.ctp";不见了

Error: [CakeViewExceptionMissingTemplateException] Template file "Errorerror500.ctp" is missing

....

如果要自定义此错误消息,请创建 srcTemplateErrorfatal_error.ctp

在升级过程之后,我的模板移动到 app_name emplates 目录并重命名为 *.php 而不是 *.ctp .我用新路径更新了 app.phpapp.default.php :

After the upgrade procedure my templates moved to app_name emplates directory and renamed to *.php instead of *.ctp . I updated the app.php and app.default.php with the new paths:

'App' => [
        'namespace' => 'App',
        'encoding' => env('APP_ENCODING', 'UTF-8'),
        'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
        'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
        'base' => false,
        'dir' => 'src',
        'webroot' => 'webroot',
        'wwwRoot' => WWW_ROOT,
        //'baseUrl' => env('SCRIPT_NAME'),
        'fullBaseUrl' => false,
        'imageBaseUrl' => 'img/',
        'cssBaseUrl' => 'css/',
        'jsBaseUrl' => 'js/',
        'paths' => [
            'plugins' => [ROOT . DS . 'plugins' . DS],
            'templates' => [ROOT . DS . 'templates' . DS],
            'locales' => [ROOT . DS  . 'Locale' . DS],
        ],
    ],

但应用程序仍然在寻找带有 .ctp 扩展名和 srcTemplate...

But still the application is looking for the template files with .ctp extension and under srcTemplate...

我错过了什么?

推荐答案

根据我的经验:

将 CakePHP 3.x 升级到 4.x

  • 作曲家更新
  • 从 --level 0 到 2 运行 phpstan 并在审查器中修复您的代码或测试
  • 阅读 4.0 迁移指南:https://book.cakephp.org/4/en/appendices/4-0-migration-guide.html
  • 阅读 4.0 升级指南:https://book.cakephp.org/4/en/appendices/4-0-upgrade-guide.html步骤:
  • 安装升级工具
  • 重命名语言环境文件
  • 重命名模板文件
  • 重命名模板和区域设置文件后,请确保将 App.paths.locales 和 App.paths.templates 路径更新为正确.
  • 从您的应用程序编写器文件中删除所有 cakephp/* (cakephp3) 包,还有 phpstan、代码标准、phpunit、.. 运行 composer update
  • 应用 Rector 重构
  • composer require --update-with-dependencies "phpunit/phpunit:^8.0"
  • composer require --update-with-dependencies "cakephp/cakephp:4.0.*"
  • 在您的应用程序文件夹中安装新的 cakephp4.示例:mkdir cakephp4 &&cd cakeph4;并运行 composer create-project --prefer-dist cakephp/app:4.* .;
  • 将旧的 cakephp 文件与 cakephp4 文件夹中的文件进行比较,更新所有文件并复制丢失的文件
  • 删除 cakephp4 和升级文件夹
  • 不要忘记在你的 php 文件顶部添加 <?php declare(strict_types=1);
  • composer cs-check 然后 composer cs-fix
  • composer update
  • run phpstan from --level 0 to 2 and fix your code or test in scrutinizer
  • read 4.0 Migration Guide : https://book.cakephp.org/4/en/appendices/4-0-migration-guide.html
  • read 4.0 Upgrade Guide : https://book.cakephp.org/4/en/appendices/4-0-upgrade-guide.html Steps:
  • Install the upgrade tool
  • Rename locale files
  • Rename template files
  • Once you've renamed your template and locale files, make sure you update App.paths.locales and App.paths.templates paths to be correct.
  • From your app composer file remove all cakephp/* (cakephp3) packages, also phpstan, code standards, phpunit,.. run composer update
  • Applying Rector Refactorings
  • composer require --update-with-dependencies "phpunit/phpunit:^8.0"
  • composer require --update-with-dependencies "cakephp/cakephp:4.0.*"
  • Install fresh cakephp4 inside your app folder. Example: mkdir cakephp4 && cd cakeph4; and run composer create-project --prefer-dist cakephp/app:4.* .;
  • compare your old cakephp files with files from cakephp4 folder, update all and copy missing files
  • delete cakephp4 and upgrade folders
  • don't forget at top of you php files to add <?php declare(strict_types=1);
  • composer cs-check then composer cs-fix

这篇关于CakePHP:从 3.6.x 升级到 4.0“缺少模板异常"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆