Zend / PHP:如何对控制器和映射器php类执行HTTP POST

时间:2016-03-24 13:38:10

标签: java php android mysql zend-framework

我们的Android应用程序应该对运行PHP Zend的服务器执行POST请求,以便在MySQL中保存数据。根据Zend MVC,我们的老板告诉我们实施以下课程:

GcmUsersController.php     

intValue()

GcmUsersMapper.php

boolean greater = fraction.intValue() >= MAX_VALID_RATIO

我们的应用Android应该执行POST HTTP的网址是哪个?这就是我们所做的:

class GcmUsersController extends AppController
{
 public function registationAction()
  {
   if($this->getRequest()->isPost()){
      $token = $this->getRequest()->getPost('token');
      $android_id = $this->getRequest()->getPost('android_id');
      $name = $this->getRequest()->getPost('name');
      $gcm = new Application_Model_GcmUsersMapper();
      $info = array(
          "tokenid" => $token,
          "gcm_regid" => $android_id,
          "name" => $name,
          "email" => "a@a.it"
      );
      $gcm->insert2($info, "GcmUsers");
   }
}
?>

因为我们认为URL中的注册和控制器中的注册操作之间存在绑定,但它不起作用。哪种方法正确?

1 个答案:

答案 0 :(得分:0)

解决方案就是这样:

内部视图 - >脚本创建目录apnsdevices并在其中插入文件registrationapple.phtml,即:

<?php 
  echo $this->data;
?>

然后,这是ApnsDevicesMapper.php

<?php 
class Application_Model_ApnsDevicesMapper extends Application_Model_AppMapper
{

protected $_mvcTable = 'ApnsDevices';

protected $_dbTable = 'apns_devices';

public function registration($device_id, $token) {
    $where = "deviceuid = '".$device_id."'";
    $c = $this->count($this->_mvcTable,$this->_dbTable,$where);
    if($c == 0){
        $info = array(
            "devicetoken" => $token,
            "deviceuid" => $device_id
        );
        $this->insert2($info, "ApnsDevices");

    }
    return $c;   
}


}
?>

这是ApnsdevicesController.php

<?php
class ApnsdevicesController extends AppController
{
public function registrationappleAction()
{
    if($this->getRequest()->isPost()){
        $token = $this->getRequest()->getPost('token');
        $device_id = $this->getRequest()->getPost('device_id');
        $apns = new Application_Model_ApnsDevicesMapper();
        $c = $apns->registration($device_id, $token);
        $this->view->data = $c;
    }
}

}

?>

最后,我可以将POST方法执行到以下URL:

http://server_path/apnsdevices/registrationapple