Micro Applications Complied Error

<?php

$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
    __DIR__ . '/models/'
))->register();

$di = new \Phalcon\DI\FactoryDefault();
$di->set('db', function(){
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname' => 'test',
        'charset' => 'utf8',
    ));
});

$app = new \Phalcon\Mvc\Micro($di);

$app->get('/api/product', function() use ($app) {
    $phql = "SELECT * FROM product";
    $products = $app->modelsManager->executeQuery($phql);
    $d = array();
    foreach ($products as $product) {
        $d[] = array(
            'id' => $product->id,
            'data' => $product->data,
        );
    }
    echo json_encode($d);
});

$app->handle();

The error is:

( ! ) Fatal error: Uncaught exception 'Phalcon\Mvc\Micro\Exception' with message 'The Not-Found handler is not callable or is not defined' in C:\wamp\www\api\index.php on line 34
( ! ) Phalcon\Mvc\Micro\Exception: The Not-Found handler is not callable or is not defined in C:\wamp\www\api\index.php on line 34
Call Stack
#   Time    Memory  Function    Location
1   0.0013  259720  {main}( )   ..\index.php:0
2   0.0020  275472  handle ( )  ..\index.php:34

How can you fix this error?



32.6k

Hi Can you upload index.php file ?



10.9k

I use commmand: phalcon create-project --name proj -type=m, which m is stand for Micro applications, that is OK now, I think that the reason is the handle should implement notFound, otherwise Uncaught exception will throw.....



1.5k

The request doesn't match a route, this it will return the Not-Found handler. But this handler is not set so it throws an exeptions.