0

I define a variable in my view, called Student. In my view, how to I display the Student object as a JSON?

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

In my preview.phtml view, i have the following:

<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 Answer 1

1

Put quotes around php tag

<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>
1
  • This will return the json results generated by php as a JavaScript string and not a js object notation.
    – zen.c
    May 14, 2012 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.