Android HttpGet запрашивает indexAction - PullRequest
0 голосов
/ 27 декабря 2011

мой запрос 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 Ответ

0 голосов
/ 27 декабря 2011

Я нашел ответ. Это на самом деле поведение Zend Framework. Если элемент 'id' не найден в запросе GET, он будет перенаправлен на indexAction вместо getAction.

Пример:

«GET localhost / student» будет перенаправлен на indexAction, а «GET localhost / student / 23» будет перенаправлен на getAction. (23 - это идентификатор)

Нашел в Zend Framework: руководство для начинающих, Викрам Васвани.

...