2013-06-24 55 views
0

我已經創建了一組類,並且想使用Zend路由器路由它們。我可以使用沒有Zend結構的Zend路由器嗎?

我的結構遵循以下模式:

/php/ 
    /REST/ 
     index.php 
    ClassOneService.php 
    ClassTwoService.php 
    ClassThreeService.php 

我想有機會獲得跨越URL類的方法(ClassOneService.php,...,ClassNService.php),例如:

class ClassOneService extends Connect { 
    public function test() { 
     echo 'hello'; 
    } 
} 

跨越

http://localhost/php/REST/classe_one/test 

我的問題是:我可以在沒有在Zend中轉換我的應用程序格式的情況下使用Zend的系統路由嗎?

不想使用MVC模式,也不想將我的類擴展到Zend Controller的類,只需使用Zend路由器路由我的方法。

回答

1

是的,你可以。

複製圖書館/ Zend的文件夾到你的應用程序的路徑,然後做:

require_once 'Zend/Controller/Router/Rewrite.php'; 
require_once 'Zend/Controller/Router/Route.php'; 

$rewrite = new Zend_Controller_Router_Rewrite(); 

$rewrite->addRoute(.....)); 
+0

好了,但我把德addRoute裏面?我試圖做此'$ rewrite-> addRoute( 'class_one',新Zend_Controller_Router_Route中( 'class_one /', 陣列( '控制器'=> 'ClassOneService', '動作'=> '測試' ) ));'但不工作,即時通訊不知道我是否可以在這裏使用任何類,並在文檔中沒有任何提到使用ZendController作用域的其他類。 –

+1

您可以使用zend_route設置路由,但是您需要編寫自己的代碼來管理重定向。 'foreach($ rewrite-> getRoutes()as $ route){if($ route-> match($ path){// matched,get route parts and redirect}}' – Rijndael

+0

Thanks !!這幫了我很多!可以實現路由到我的類。 –