2017-05-17 71 views
0

我有一個小問題slimphp路由器:Slimphp 3嵌套組不工作

$app->group('/api', function() use ($app) { 

    // Library group 
    $this->group('/library', function() use ($app) { 

     // Get book with ID 
     $this->get('/books/:id', function ($req, $res) { 
      echo "books"; 
     }); 

     // Update book with ID 
     $this->put('/books/:id', function ($req, $res) { 

     }); 

     // Delete book with ID 
     $this->delete('/books/:id', function ($req, $res) { 

     }); 

    }); 

}); 

發送GET到/ API /庫/書籍/ 1給我一個Page not found錯誤,問題出在哪裏。

編輯:

的.htaccess

RewriteEngine On 

# Some hosts may require you to use the `RewriteBase` directive. 
# If you need to use the `RewriteBase` directive, it should be the 
# absolute physical path to the directory that contains this htaccess file. 
# 
# RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 

PS:一個簡單的app->get工作沒有任何問題,

+0

?你似乎在混合每個代碼。 – meun5

+0

我正在使用slim 3 – karim

+0

您可以添加您的網絡服務器配置(即.htaccess)嗎? – meun5

回答

0

它找不到一樣苗條3種用途{id}作爲佔位符,而不是作爲:id修身2沒有。您是否使用苗條2或3渺茫。因此碼將

$this->get('/books/{id}', function ($request, $response, $args) { 
    ... 
}); 

發現在Slim 3 Documentation for Route Placeholders