Phalcon ispatcher обнаружил циклическую маршрутизацию

Я создаю новый проект с фреймворком Phalcon.

Для начала, моя среда:

  • Phalcon 3.2.12

  • Windows 10

  • Xampp / PHP 7.2

В настоящее время я создал одну страницу входа в индекс. Когда я запускаю свое приложение, у меня появляется это сообщение:

Неустранимая ошибка: Uncaught Phalcon \ Mvc \ Dispatcher \ Exception: Диспетчер имеет
обнаружил циклическую маршрутизацию, вызывающую проблемы со стабильностью в
\ Public \ index.php: 32

Строка 32:

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

Есть мой диспетчер в services.php :

$di->setShared('dispatcher', function () use ($di) {
$evManager = $di->getShared('eventsManager');

$evManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
switch ($exception->getCode()) {
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'show404'
));

return false;
}
});

$dispatcher = new PhDispatcher();
$dispatcher->setEventsManager($evManager);
return $dispatcher;
});

Есть мой IndexController :

class IndexController extends ControllerBase
{
public function indexAction()
{
$this->view->setLayout('login');
}

public function show404Action()
{
$this->view->setLayout('login');
$this->response->setStatusCode(404, "Not Found");
$this->view->pick('index/404');
}
}

Есть мой ControllerBase :

public function beforeExecuteRoute($dispatcher)
{
$isValid = true;

// check auth
if ($dispatcher->getControllerName() !== 'index') {
$isValid = false;

$this->view->disable();

$this->response->setStatusCode(401, 'Vous devez vous identifier pour     accéder à votre environnement.');

if (!$this->request->isAjax()) {
$this->response->redirect('index');
}
}

return $isValid;
}

index.php

define('APP_PATH', realpath('..'));

/**
* Define APPLICATION_ENV (DEV,STAGING,PREPROD,PROD)
*
* @var APPLICATION_ENV string
*/
defined('APPLICATION_ENV') || define('APPLICATION_ENV',     (isset($_SERVER['APPLICATION_ENV']) ?     $_SERVER['APPLICATION_ENV'] : 'PROD'));

/**
* Read the configuration
*/
$config = include APP_PATH . "/app/config/" . strtolower(APPLICATION_ENV) .     ".config.php";

/**
* Read auto-loader
*/
include APP_PATH . "/app/config/loader.php";

/**
* Read services
*/
include APP_PATH . "/app/config/services.php";

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

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

Если я поставлю var_dump в начале метода beforeExecuteRouteЯ не вижу результат var_dump,

У тебя есть идея?

Спасибо

0

Решение

вероятно, вы ожидаете чего-то, что не может быть найдено. Попробуй переименовать show404 в showNotFound, вы можете проверить $ dispatcher-> getControllerName () и getActionName () во время события afterExecuteRoute, чтобы увидеть, почему ваш обработчик или действие никогда не могут быть найдены

public function showNotFoundAction()
{
$this->view->setLayout('login');
$this->response->setStatusCode(404, "Not Found");
$this->view->pick('index/404');
}

А также

            $dispatcher->forward(array(
'controller' => 'index',
'action' => 'showNotFound'
));
0

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

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

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector