php - How i get data and returned in json format in zf2? -


I used the mongo odm query to get the data according to the id, I want to get query data and this Want to return the data to json format, how do I do this? Here is my code:

  public function loadAction () {$ id = (int) $ this- & gt; Params () - & gt; Fromoutout ('id', 0); $ Dm = $ this- & gt; GetServiceLocator () - & gt; Obtain ('doctrine.documentmanager.odm_default'); $ Data = $ this- & gt; DM- & gt; createQueryBuilder ('Calendar \ Document \ Event') - & gt; Region ('Calendar_ID') - & gt; Equal ($ ID) - & gt; GetQuery () - & gt; carry about ( ); // $ count_tags = $ eventdata-> Count (); $ Array = array (); If ($ data & amp; is_null ($ data) & amp; is_object ($ data)) {foreach (dollar's data = $ form => gt; $ value) {$ array [] = $ value; }} Return $ $-> GetResponse () - & gt; Set Content (Jason :: Encoded ($ array)); }    

You can call it

  New Jason Möldel ( Return $ array-variable);   

You may need to import

  Zend \ View \ Model \ JsonModel;   

Hope that helps

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -