I’ve set up the following route in CakePHP 1.2:
Router::connect(
"/inbound/:hash",
array('controller' => 'profiles', 'action' => 'inbound', '[method]' => 'POST'),
array('hash' => '[0-9a-zA-Z]+'),
array('pass' => array('hash'))
);
Here are my request headers (via drupal_http_request()):
POST /inbound HTTP/1.0
Host: mysite.dev
User-Agent: Drupal (+http://drupal.org/)
Content-Length: 45
hash=test
However, I’m getting a 404 in response when I post. If I remove the parameter “:hash” from my route definition I get a 200. But in both cases the action in my controller does not get the passed parameter (hash).
I’m unsure what I’m doing wrong, as I appear to be doing what is in the doc.
The purpose of the
passparameter is to define which route parameters are being passed to the action. So what you are doing there is creating a route that connects to URLs like this:where
foowould be passed as a parameter to the controllersinboundaction.Your request however points to
/inboundonly, so this won’t match your route as the parameter is missing, and consequently you are receiving a 404.The data in the body of your POST request is being passed as regular POST data, ie it would be available via the controllers
paramsproperty:So either remove the
hashparameter in the route and access the data via$this->params['form'], or pass the data in the URL where thehashparameter is defined:then you can access it in your controller action like this: