CakePHP:从 3.6.x 升级到 4.0“缺少模板异常"

CakePHP: upgrade from 3.6.x to 4.0 quot;Missing Template Exceptionquot;(CakePHP:从 3.6.x 升级到 4.0“缺少模板异常)
本文介绍了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“缺少模板异常"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)