2012-05-11 28 views
0

我在我的视图中定义了一个名为Student的变量。在我看来,如何将Student对象显示为JSON?如何在Zend Framework中以JSON格式返回Application_Model 1.11

public function previewAction() 
{ 
    // ... 
    $this->view->student = $student; 
} 

在我preview.phtml观,我有以下几点:

<script> 
    // this doesn't return the Application_Model as a JSON object in the html  
    var studentData = <?php echo Zend_Json::encode($this->student); ?>; 
</script> 
+2

请问这个回报把双引号? – skafandri

回答

1

围绕PHP标签

<script> 
    // this doesn't return the Application_Model as a JSON object in the html  
    var studentData = "<?php echo Zend_Json::encode($this->student); ?>"; 
</script> 
+0

这将返回由php生成的json结果作为JavaScript字符串而不是js对象表示法。 –