Skip to main content
  1. Posts/

Phalcon Error: Dispatcher has detected a cyclic routing causing stability problems

·1 min·
phalcon phalcon php
Table of Contents

Issue
#

Saat membuat website dengan framework Phalcon, Anda menemukan error berikut saat mengakses halaman.

Dispatcher has detected a cyclic routing causing stability problems
#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('Dispatcher has ...', 1)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /home/user/public_html/public/index.php(29): Phalcon\Mvc\Application->handle()
#3 {main}

Solution
#

Saat mengakses halaman yang error, Dispatcher akan menampilkan error tersebut apabila konfigurasi action tidak ditentukan atau konfigurasi pada controller yang belum sesuai.

$di->set(
    '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' => 'Error',
                                'action'     => 'index',
                            )
                        );
                        return false;
                }
            }
        );
        $dispatcher = new PhDispatcher();
        $dispatcher->setEventsManager($evManager);
        return $dispatcher;
    },
    true
);

Untuk itu agar dapat melihat error yang sebenarnya pada halaman yang diakses maka Anda dapat menghapus atau comment (//) bagian kode dispatcher seperti contoh diatas.

Jika sudah maka error yang tampil akan berbeda.

Atau Anda dapat mengubah dispatcher menjadi seperti berikut.

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

    // Attach event handlers, if any

    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
});

Related

Error PHP - move_uploaded_file() Unable to move file from tmp to dir
·1 min
php php
Install Redis di Linux
·1 min
linux php linux
Install Memcached di Linux
·1 min
linux php linux
Install APCu di Linux
·1 min
linux php linux
Cara Membuat iFrame HTML
·1 min
html php html
Install Nginx dengan PHP-FPM dan Userdir
·9 mins
nginx centos linux php nginx