CakePHP: upgrade from 3.6.x to 4.0 “Missing Template Exception”

天涯浪子 提交于 2021-02-19 07:55:30

问题


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

Error: [Cake\View\Exception\MissingTemplateException] Template file "Error\error500.ctp" is missing

....

If you want to customize this error message, create src\Template\Error\fatal_error.ctp

After the upgrade procedure my templates moved to app_name\templates 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],
        ],
    ],

But still the application is looking for the template files with .ctp extension and under src\Template\...

What am I missing?


回答1:


From my experience:

Upgrade CakePHP 3.x to 4.x

  • 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


来源:https://stackoverflow.com/questions/60260091/cakephp-upgrade-from-3-6-x-to-4-0-missing-template-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!