CakePHP: upgrade from 3.6.x to 4.0 quot;Missing Template Exceptionquot;(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.php
和 app.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 runcomposer 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
thencomposer cs-fix
这篇关于CakePHP:从 3.6.x 升级到 4.0“缺少模板异常"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CakePHP:从 3.6.x 升级到 4.0“缺少模板异常"
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01