Rest route not found / recognized #264
-
I'm already feeling sorry to post such a recurring question but I'm somehow not finding any solution.
Contents of .htaccess: <IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule> Contents of index.php (shortened): <?php
use Phalcon\AutoLoad\Loader;
use Phalcon\Mvc\Micro;
use Phalcon\Di\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Config\ConfigFactory;
$loader = new Loader();
$loader->setNamespaces(
[
'PhlcnAppRest\DB' => __DIR__ . '/models/',
]
);
$loader->register();
$container = new FactoryDefault();
$configFactory = new ConfigFactory();
// getting db connections
...
$app = new Micro($container);
$app->get(
'/countries',
function () use ($app) {
$phql = 'SELECT id, iso3, name '
. 'FROM PhlcnAppRest\DB\Countries '
. 'ORDER BY name'
;
$countries = $app
->modelsManager
->executeQuery($phql)
;
$data = [];
foreach ($countries as $country) {
$data[] = [
'id' => $country->id,
'iso3' => $country->iso3,
'name' => $country->name
];
}
echo json_encode($data);
}
);
//... some other routes defined according to tutorial...
$app->handle($_SERVER["REQUEST_URI"]);` Also a not found handler is defined. The not found handler is always called when I call the url:
According to my log rewrite seems to be working properly:
Don't really know where it went wrong. Thanks in advance for any kind of indication on how to solve my issue! :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Mate, you code looks fine. But the issue is the URL... you open : http://localhost/projects/Phalcon/api/countries and i think your code is in that phalcon folder? so... try this: $app->get(
'/projects/Phalcon/api',
function () use ($app) {
$data = [];
echo json_encode($data);
}
);
$app->get(
'/projects/Phalcon/api/countries',
function () use ($app) {
$data = [];
echo json_encode($data);
}
); Some recommendation: In apache httpd-vhosts.conf
And do not forget to set in host file in windows C:\Windows\System32\drivers\etc\ - host
And restart apache service after that :P |
Beta Was this translation helpful? Give feedback.
-
I really appreciate it; you brightened my day. basketball stars |
Beta Was this translation helpful? Give feedback.
Mate, you code looks fine. But the issue is the URL... you open : http://localhost/projects/Phalcon/api/countries and i think your code is in that phalcon folder?
so... try this:
Some recommendation:
Try to use vhosts in Apache - then url will be like http://project.api/countries (for example):
In apache httpd-vhosts.conf