•   30.11.2024
#PHP #Phalcon Framework

Upgrade & update some class/function from Phalcon 3.4 to 5.0

1 phút đọc
  • Upgrade on base:

    • Linux Ubuntu 20.04 LTS
    • PHP 8.1
  • In filepath app/config.php

    • Moved Phalcon\Config to Phalcon\Config\Config
  • In filepath app/loader.php

    • Moved Phalcon\Loader to \Phalcon\Autoload\Loader

    • Moved registerDirs() to setDirectories()

    • Moved registerNamespaces() to setNamespaces()

    • Moved registerClasses() has been renamed to setClasses()

  • In filepath app/config/router.php

    • Moved $router->handle() to $router->handle($_SERVER['REQUEST_URI'] ?? '/')
  • In filepath public/index.php

  • In filepath app/config/services.php change key off array

instead of

$volt->setOptions([
    'compiledPath' => $config->application->cacheDir,
    'compiledSeparator' => '_'
]);

update to

$volt->setOptions([
    'path' => $config->application->cacheDir,
    'separator' => '_'
]);
  • Access to 404 page

    • Moved PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND to Exception::EXCEPTION_HANDLER_NOT_FOUND and use Phalcon\Dispatcher\Exception;

    • Moved PhDispatcher::EXCEPTION_ACTION_NOT_FOUND to Exception::EXCEPTION_ACTION_NOT_FOUND and use Phalcon\Dispatcher\Exception;

  • Moved all Phalcon\DI to Phalcon\Di\Di

  • Phalcon session error:

$di->set('session', function() use ($di) {
    $session = new Phalcon\Session\Manager();
    $files = new Phalcon\Session\Adapter\Stream();
    $session->setAdapter($files)->start();

    return $session;
});
  • Phalcon flash error:
/**
 * Register the session flash service with the Twitter Bootstrap classes
 */
$di->set('flash', function () {
    $flash = new FlashSession();
    $flash->setAutomaticHtml(true);
    $flash->setCssClasses([
        'error'   => 'alert alert-danger',
        'success' => 'alert alert-success',
        'notice'  => 'alert alert-info',
        'warning' => 'alert alert-warning'
    ]);

    return $flash;
});

see link


Hashtags: