繁体   English   中英

如何在Zend Framework 1.11中以JSON格式返回Application_Model

[英]How to return an Application_Model in JSON format in Zend Framework 1.11

我在我的视图中定义了一个名为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>

将引号放在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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM