开发者

Custom ZendRestController URL

Iam developing a Zend RestController and i have to generate the response as xml format. I added context switching and hence i could see my xml output with the url like:

http://localhost/app/public/api/key/123456/format/xml/

(where "api" is controller, key=123456, passed via GET)

But what i want is, the url should be something like:

http://localhost/app/public/api/v1/abc.xml/

(For the moment, leave the "key" parameter, as later i would be sending it through curl post)

How can i achieve this? Do i need to tweak something with the url? Iam mainly concerned with changing t开发者_开发技巧he "format/xml" to "abc.xml"


I have routes setup in my application bootstrap as:

/*
 * ReWrite Rules and Routes
 */
protected function _initRoutes() {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    // New Route
    $router->addRoute('api', new Zend_Controller_Router_Route('/api/:key.xml', array( 'module'=>'index', 'controller' => 'api', 'action' => 'index', 'key'=>'')));
}

And then use the url helper as:

<a href="<?= $this->url(array('key'=>123456), 'api') ?>">API Call</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜