We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Micro App , Routing doesn't match

when i run those code

<?php

use Phalcon\Mvc\Micro;

$app = new Micro();

$app->get(
    '/orders/display/{name}',
    function ($name) {
        echo "<h1>This is order: {$name}!</h1>";
    }
);

$app->handle();

when i try to visit "/orders/display/hello" error occurred

Fatal error: Uncaught Phalcon\Mvc\Micro\Exception: Not-Found handler is not callable or is not defined in /home/vagrant/test-phalcon/index.php:14 Stack trace: #0 /home/vagrant/test-phalcon/index.php(14): Phalcon\Mvc\Micro->handle() #1 {main} thrown in /home/vagrant/test-phalcon/index.php on line 14

so i add some code like this

$app->notFound(
    function () use ($app) {
        $app->response->setStatusCode(404, 'Not Found');
        $app->response->sendHeaders();

        $message = 'Nothing to see here. Move along....';
        $app->response->setContent($message);
        $app->response->send();
    }
);

Try to visit "/orders/display/hello", then the page display

Nothing to see here. Move along....

I consider it should display

<h1>This is order: hello!</h1>

is anyone know how to solved this problem, thanks.

Your web/app server is misconfigured. Paste your config here, and logs, what does it say for absolute path when you trigger 404?



585
Accepted
answer

Thanks for your reply, sovled the problem by

php -S 192.168.33.10:8888 ----> php -S 192.168.33.10:8888 .htrouter.php

.htrouter.php

<?php
if (!file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
    $_GET['_url'] = $_SERVER['REQUEST_URI'];
}
return false;

Your web/app server is misconfigured. Paste your config here, and logs, what does it say for absolute path when you trigger 404?

Yeah, but that's only temp solution, how do you plan to fix it long term on a real web server?