2016-08-24 44 views
1

我在蛋糕PHP3中創建了其他API,我需要將一些API版本添加到端點。 例如:杜梅因 - www.test.com 版本 - /test/api/v1/ 所以用戶端點喜歡被www.test.com/test/api/v1/users蛋糕PHP3其餘的API獲取圖像的公開URL

我已經改變了routes.php文件,如下。

Router::scope('/test/api/v1/', function (RouteBuilder $routes) { 

上述改變是在終端工作正常,但當我試圖讓公衆形象的URL,在webroot/img目錄圖片如下它說Controller class Img is missing

http://test.com/test/api/v1/img/cake.png

  1. 我是用正確的蛋糕PHP3如何更改端點URL?
  2. 如果是這樣,我怎麼能得到如上webroot/img圖像的公共URL?

回答

1

在CakePHP中,創建不同版本的REST API作爲單獨的插件(例如插件ApiV10)是一種很好的做法。

內插件routes.php文件添加這樣的:

use Cake\Routing\RouteBuilder; 
use Cake\Routing\Router; 
Router::extensions(['json']); 
Router::plugin(
    'ApiV10', 
    ['path' => '/api/v1'], 
    function (RouteBuilder $routes) { 
     $routes->connect(
      '/autosuggestions/locations', 
      ['controller' => 'Autosuggestions', 'action' => 'locations','_ext' => 'json'] 
      ); 
     $routes->connect('/users', ['controller' => 'Users', 'action' => 'index']); 
     $routes->fallbacks('DashedRoute'); 
    } 
); 

在你的控制器方法組數據陣列完整路徑根目錄/ IMG/yourimages.jpg。全路徑也可以在實體

http://book.cakephp.org/3.0/en/orm/entities.html#accessors-mutators

修改