我在视图中定义了一个名为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>
答案 0 :(得分: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>