[英]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.