Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two action helpers for doing exactly this. you can re-use your actions for multiple contexts with the ajaxContext or contextSwitch action helpers. The context switch is generally the more useful in my experience, and it can even automatically serialize the data you assign to the view in your action for json responses so there is no need for a view script.</p> <p>you initialise the context switch like this:</p> <pre><code>class MyController extends Zend_Controller_Action { public function init() { $contextSwitch = $this-&gt;_helper-&gt;getHelper('contextSwitch'); $contextSwitch-&gt;addActionContext('index', 'json') -&gt;initContext(); } public function indexAction() { $this-&gt;view-&gt;items = My_Model::fetchAll(); } } </code></pre> <p>The above will add a context of json to the context switch, and when the action is called with the request parameter 'format' set, it will automatically serialize the content, in this case giving a json array of the items returned by My_Model::fetchAll();</p> <p>The format parameter can either be passed in the url "/my/index/format/json" or with a get query "/my/index?format=json"</p> <p>The real magic is that the context switch also sets the appropriate headers for the response type, such as content-type. </p> <p>You can even specify your own contexts, and the headers to send. Read more about the context switch <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch" rel="nofollow noreferrer">here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload