Android HttpGet запрашивает indexAction
Мой запрос HttpGet вызывает мой indexAction вместо getAction. В чем дело?
Вот мои коды:
public function getAction() {
$id = $this->_getParam('id');
if(!$id)
{
$this->getResponse()
->setHttpResponseCode(400)
->setBody("no id");
return;
}
try
{
$q = Doctrine_Query::create()
->from('Milotin_Model_Locations l')
->where ('l.id=?', $id);
$result = $q->fetchArray();
if(count($result) == 1)
{
$this->getResponse()
->setHttpResponseCode(200)
->setBody(json_encode($result));
}
}
catch(Exception $e)
{
$this->getResponse()
->setHttpResponseCode(500)
->setBody($e->getMessage());
}
}
public function indexAction() {
}
А вот мой код в Android:
private static void getLoc()
{
final HttpResponse response;
final HttpGet getRequest = new HttpGet(LOCATION_URI + "?geolat=" + geoLat + "&geolong=" + geoLong);
try {
response = mHttpClient.execute(getRequest);
if(response.getStatusLine().getStatusCode() == 200)
{
//do something
}
} catch (ClientProtocolException e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
}
Мой HttpPost работает правильно (он вызывает postAction), есть объяснения?
Благодарю.
1 ответ
Решение
Я нашел ответ. Это на самом деле поведение Zend Framework. Если элемент 'id' не найден в запросе GET, он будет перенаправлен на indexAction вместо getAction.
Пример:
"GET localhost/student" будет перенаправлен на indexAction, а "GET localhost/student/23" будет перенаправлен на getAction. (23 - это идентификатор)
Нашел его в Zend Framework: Руководство для начинающих, Викрам Васвани.