Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Zend Framework 2中使用ajax和json编码_Php_Jquery_Ajax_Json_Zend Framework2 - Fatal编程技术网

Php 如何在Zend Framework 2中使用ajax和json编码

Php 如何在Zend Framework 2中使用ajax和json编码,php,jquery,ajax,json,zend-framework2,Php,Jquery,Ajax,Json,Zend Framework2,我使用jquery尝试了一个简单的ajax应用程序,错误是每个数据对象都是空的。有人能帮我吗? 下面是mycode: protected $mysqlAdapter; protected $studentid; protected $fullname; protected $birthdate; protected $placebirth; protected $gender; protected $id_religion; protected $nm_religion; protected $

我使用jquery尝试了一个简单的ajax应用程序,错误是每个数据对象都是空的。有人能帮我吗? 下面是mycode:

protected $mysqlAdapter;
protected $studentid;
protected $fullname;
protected $birthdate;
protected $placebirth;
protected $gender;
protected $id_religion;
protected $nm_religion;
protected $stdaddr;
protected $stdphone;
protected $stdcellular;
protected $stdemail;

public function indexAction()
{
    $request = $this->getRequest();
    $response = $this->getResponse();

    $nm_pd = $this->request->getPost('nm_pd');
    $tgl_lahir = $this->request->getPost('tgl_lahir');
    $id_agama = $this->request->getPost('id_agama');
    $nm_agama = $this->request->getPost('nm_agama');

    $dbAdapter = $this->getMysqlAdapter();
    $sql = new Sql($dbAdapter);
    $all = $sql->select();
    $all->from('v_datadetail_feeder');
    $all->where(array('studentid' => 11509002));
    $statement = $sql->prepareStatementForSqlObject($all);
    $result = $statement->execute();

    foreach ($result as $rs) {
        $studentid = $this->$rs['studentid'];
        $fullname = $this->$rs['fullname'];
        $birthdate = $this->$rs['birthdate'];
        $placebirth = $this->$rs['placebirth'];
        $gender = $this->$rs['gender'];
        $id_religion = $id_agama;
        $nm_religion = $nm_agama;
        $stdaddr = $this->$rs['stdaddr'];
        $stdphone = $this->$rs['stdphone'];
        $stdcellular = $this->$rs['stdcellular'];
        $stdemail = $this->$rs['stdemail'];
        $data = array('fullname'=>$fullname,
                      'studentid'=>$studentid,
                      'birthdate'=>$birthdate,
                      'placebirth'=>$placebirth,
                      'gender'=>$gender,
                      'id_agama'=>$id_religion,
                      'nm_agama'=>$nm_religion,
                      'stdaddr'=>$stdaddr,
                      'stdphone'=>$stdphone,
                      'stdcellular'=>$stdcellular,
                      'stdemail'=>$stdemail,
                      );
        $response->setContent(Json::encode($data));         
    }
    return $response;
}
结果是: {“fullname”:null,“studentid”:null,“birthdate”:null,“placeborning”:null,“性别”:null,“id_agama”:null,“nm_agama”:null,“stdaddr”:null,“stdphone”:null,“stdcytellular”:null,“stdemail”:null}


您必须使用ZF2 JsonModel(),在module.config.php文件中启用JsonStrategy

'view_manager' => array (
        'strategies' => array (
            'ViewJsonStrategy' 
        ) 
),
并在控制器内像这样使用它:

$view = new JsonModel($jsonArray);
$view->setTerminal(true); // to disable layout
return $view;

您必须使用ZF2 JsonModel(),在module.config.php文件中启用JsonStrategy

'view_manager' => array (
        'strategies' => array (
            'ViewJsonStrategy' 
        ) 
),
并在控制器内像这样使用它:

$view = new JsonModel($jsonArray);
$view->setTerminal(true); // to disable layout
return $view;

您必须使用ZF2 JsonModel(),在module.config.php文件中启用JsonStrategy

'view_manager' => array (
        'strategies' => array (
            'ViewJsonStrategy' 
        ) 
),
并在控制器内像这样使用它:

$view = new JsonModel($jsonArray);
$view->setTerminal(true); // to disable layout
return $view;

您必须使用ZF2 JsonModel(),在module.config.php文件中启用JsonStrategy

'view_manager' => array (
        'strategies' => array (
            'ViewJsonStrategy' 
        ) 
),
并在控制器内像这样使用它:

$view = new JsonModel($jsonArray);
$view->setTerminal(true); // to disable layout
return $view;