1

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?

Community
  • 1
  • 1
thelaw
  • 385
  • 5
  • 12

1 Answers1

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
Salines
  • 5,674
  • 3
  • 25
  • 50
  • Hi there, thanks for sharing your way to go. I just followed your way and saw, that the order of the steps "remove all cakephp3-packages" and "apply rector refactorings" must be switched. After removing cakephp-packes, rector can't apply changes due to missing classes. Despite of that, very nice. Can you shortly give an explanation or command, how to do step 2? – MikeRoss Apr 16 '20 at 10:22
  • @MikeRoss step 2: Rename locale files ?? Or? – Salines Apr 16 '20 at 11:15
  • I meant step "run phpstan from --level 0 to 2 and fix your code or test in scrutinizer" could include a short explanation of how to run this command (e.g. for me, I didn't use phpstan before). Some that might read your instructions (that worked pretty good, btw) may be thankful. – MikeRoss Apr 16 '20 at 12:54
  • @MikeRoss ```composer require --dev phpstan/phpstan``` then in console run ```./vendor/bin/phpstan analyse src plugins --level 0``` this command output some basic errors, with level 1 you have deeper outputs, etc. Try to find and fix error and Deprecations warnings. For example $this->request->.. emit Deprecated warning .. – Salines Apr 16 '20 at 13:18
  • "After removing cakephp-packes, rector can't apply changes due to missing classes." remove from composer file, not from vendor folder – Salines Apr 16 '20 at 13:20
  • 1
    Thanks for the command. Will try this with my second project. Regarding your last comment ("remove from composer file, not from vendor folder"): I removed from composer.json and then - just like you told in this step, ran composer update. Maybe, I deleted too many packages ;) – MikeRoss Apr 16 '20 at 13:24