我剛開始致力於一個簡單的寧靜服務。 的文件夾結構我已經是像這樣:Phalconphp micro mvc路由問題
root
- /api
--/api/customers.php
因此,例如在瀏覽器中,我打算叫http://domain/api/customers/fetchall
不過,我只拿到稱爲NOTFOUND處理程序。在customers.php的代碼是:
<?php
use Phalcon\DI\FactoryDefault,
Phalcon\Mvc\Micro,
Phalcon\Config\Adapter\Ini;
$di = new FactoryDefault();
$di->set('config', function() {
return new Ini("config.ini");
});
$app = new Micro($di);
/**
* Create new customer
*/
$app->post('/create', function(){});
/**
* Retrieve all customers
*/
$app->get('/fetchall', function() use ($app) {
$data = array();
$data[] = array(
'id' => '123456',
'name' => 'customerName',
);
echo json_encode($data);
});
/**
* Find customer by name
*/
$app->get('/search/{name}', function($name){});
/**
* Find customer by email
*/
$app->get('/search/{email}', function($email){});
/**
* Find customer by postcode
*/
$app->get('/search/{postcode}', function($postcode){});
/**
* Move a customer
*/
$app->put('/move/{oldpostcode}/{newpostcode}', function($oldpostcode, $newpostcode){});
/**
* Delete customer
*/
$app->delete('/delete/{id:[0-9]+}', function($id) use ($app) {
$response = new Phalcon\Http\Response();
$response->setJsonContent(array('status' => 'OK'));
return $response;
});
$app->notFound(function() use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo 'This is crazy, but this page was not found!';
});
//echo $_SERVER['REQUEST_URI'];
$app->handle();
如果我改用/,而不是在作品/使用fetchall然後,但它也可以匹配任何URL以及這也是白搭。
提前感謝幫助。 感謝 亞當
用這個在Micro v 2.0.8中獲得正確的URI – Emi