Совместимость Phalcon 3.0 и Phalcon 2.0

Я создал голый проект Phalcon 3.0 с Devtools 3.0, он отлично работал на моей машине
Затем я загрузил на свой веб-хостинг, и он воспроизвел сообщение об ошибке:
Argument 1 passed to Phalcon\Di\Injectable::setDI() must implement interface Phalcon\DiInterface, instance of Wegawe\Modules\Frontend\Module given in /home/wewe/web/app/modules/frontend/Module.php on line 41

Затем я понял, что мой веб-хостинг использует Phalcon 2.0 вместо Phalcon 3.0

Есть какие-то хитрости, чтобы решить эту проблему? Извините за мой плохой английский. : D

Вот мое приложение / bootstrap_web.php:

<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;

error_reporting(E_ALL);

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

try {

/**
* The FactoryDefault Dependency Injector automatically registers the services that
* provide a full stack framework. These default services can be overidden with custom ones.
*/
$di = new FactoryDefault();

/**
* Include general services
*/
require APP_PATH . '/config/services.php';

/**
* Include web environment specific services
*/
require APP_PATH . '/config/services_web.php';

/**
* Get config service for use in inline setup below
*/
$config = $di->getConfig();

/**
* Include Autoloader
*/
include APP_PATH . '/config/loader.php';

/**
* Handle the request
*/
$application = new Application($di);

/**
* Register application modules
*/
$application->registerModules([
'frontend' => ['className' => 'Wegawe\Modules\Frontend\Module'],
]);

/**
* Include routes
*/
require APP_PATH . '/config/routes.php';

echo $application->handle()->getContent();

} catch (\Exception $e) {
echo $e->getMessage() . '<br>';
echo '<pre>' . $e->getTraceAsString() . '</pre>';
}

Приложение / модули / интерфейс / module.php:

<?php
namespace Wegawe\Modules\Frontend;

use Phalcon\DiInterface;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Php as PhpEngine;
use Phalcon\Mvc\ModuleDefinitionInterface;

class Module implements ModuleDefinitionInterface
{
/**
* Registers an autoloader related to the module
*
* @param DiInterface $di
*/
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();

$loader->registerNamespaces([
'Wegawe\Modules\Frontend\Controllers' => __DIR__ . '/controllers/',
'Wegawe\Modules\Frontend\Models' => __DIR__ . '/models/',
]);

$loader->register();
}

/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Setting up the view component
*/
$di->set('view', function () {
$view = new View();
$view->setDI($this);
$view->setViewsDir(__DIR__ . '/views/');

$view->registerEngines([
'.volt'  => 'voltShared',
'.phtml' => PhpEngine::class
]);

return $view;
});
}
}

0

Решение

Вы должны изменить

$view->setDI($this);

в

$view->setDI($di);
0

Другие решения

Других решений пока нет …