Zend_Rest_Route + Chaining

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Rest_Route + Chaining

SpiffyJr
Is it possible to chain a Router_Route_Hostname to a Zend_Rest_Route? I'm attempting to redirect http://api.mydomain.com to the "api" module using a RESTful approach and I'm having no such luck. They work independently fine but when I try to combine them everything blows up. Here's the code from my bootstrap.

        public function _initRoute()
        {
                $front = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
               
                $apiRoute = new Zend_Controller_Router_Route_Hostname('api.test.dev', array('module' => 'api'));
                $restRoute = new Zend_Rest_Route($front, array(), array('api'));
               

                $router->addRoute('api', $apiRoute->chain($restRoute));
        }

And the corresponding request paramaters for http://api.test.dev/events.json

array (
  'format' => 'json',
  'controller' => 'events',
  'action' => 'index',
  'module' => 'default',
)

Any help would be greatly appreciated.

Thanks,

Kyle Spraggs (theman@spiffyjr.me)
http://www.spiffyjr.me
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Rest_Route + Chaining

Ben Scholzen 'DASPRiD'
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Rest_Route + Chaining

SpiffyJr

DASPRiD wrote
The rest-route is overriding the module given in the hostname route. You
may try this (not tested):

No good. Here is my current code:

                $front = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
               
                $apiRoute = new Zend_Controller_Router_Route_Hostname('api.blitz.com', array('module' => 'api'));
                $restRoute = new Zend_Rest_Route($front, array('module' => 'api'), array('api'));
               
                $router->addRoute('api', $apiRoute->chain($restRoute));
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Rest_Route + Chaining

SpiffyJr

Kyle Spraggs wrote
DASPRiD wrote
The rest-route is overriding the module given in the hostname route. You
may try this (not tested):

No good. Here is my current code:

                $front = Zend_Controller_Front::getInstance();
                $router = $front->getRouter();
               
                $apiRoute = new Zend_Controller_Router_Route_Hostname('api.blitz.com', array('module' => 'api'));
                $restRoute = new Zend_Rest_Route($front, array('module' => 'api'), array('api'));
               
                $router->addRoute('api', $apiRoute->chain($restRoute));
Actually, http://api.mydomain.com matches but http://api.mydomain.com/controller reverts back to the default module.
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Rest_Route + Chaining

SpiffyJr
I've put in a bunch of debug code and this is what I've got.

Zend_Rest_Route
Zend_Controller_Router_Route_Hostname
Calling chain...
hostname match();
Hostname $host: Array ( [0] => api [1] => blitz [2] => com )
Hostname returns: Array ( )
rest match();
Rest Path: Array ( [0] => events )
Rest values: Array ( [controller] => events [action] => index )
Rest defaults: Array ( [module] => api [controller] => index [action] => index )
Rest returns: Array ( [controller] => events [action] => index [module] => api )

for this code:

$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
               
// API
$apiRestRoute = new Zend_Rest_Route($front, array('module' => 'api'));
$apiHostRoute = new Zend_Controller_Router_Route_Hostname('api.blitz.com');
               
$router->addRoute('api', $apiHostRoute->chain($apiRestRoute));

The chained rest route is returning what appears to be the correct data yet I receive this error.

Exception Information:

Error Message: Invalid controller specified (events)

Stack Trace:

#0 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch()
#2 C:\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(358): Zend_Application_Bootstrap_Bootstrap->run()
#3 G:\Documents\Workspace\Blitzaroo\public\index.php(28): Zend_Application->run()
#4 {main}
Request Parameters:

array (
  'controller' => 'events',
  'action' => 'index',
  'module' => 'default',
)

So, why is it still trying to use the default module even though the Rest_Route is returning the proper data?
Kyle S
blogs @ www.spiffyjr.me
github @ www.github.com/spiffyjr
follow @ www.twitter.com/spiffyjr
coa
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Rest_Route + Chaining

coa
I think your problem could be caused by http://framework.zend.com/issues/browse/ZF-11121
I had a very similar problem, and posted a suggested fix there.

/christian