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>
zen.c
  • 678
  • 8
  • 17

1 Answers1

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>
Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • This will return the json results generated by php as a JavaScript string and not a js object notation. – zen.c May 14 '12 at 06:56