0

我在视图中定义了一个变量,称为 Student。在我看来,如何将 Student 对象显示为 JSON?

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>
4

1 回答 1

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>
于 2012-05-11T15:05:51.917 回答