php - How to handle Multidimensional Array on XML Template? -
so here code... used in project.
$app->post( '/chk_db', function () use ($app){ require_once 'lib/mysql.php'; $dx = connect_db('myphotos'); //xml response $app->response->setstatus(0); $res = $app->response(); $res['content-type'] = 'application/xml'; $view = $app->view(); $view->settemplatesdirectory('./'); $oarray = array("status"=> $dx.status, "code" => $dx.code); return $app->render('chkdb.xml', $oarray); } );
so have array input xml template (by way... json_encoded... use represent array... thanks...)
[{"objid":"1","parenetid":"10001","path":"http:\/\/localhost\/img\/1.jpg","title":"1st image","childcount":"0","owner":"jhim","comment":"hehe","inode":"0"}, {"objid":"2","parenetid":"10002","path":"http:\/\/localhost\/img\/2.jpg","title":"2nd image","childcount":"0","owner":"nemy","comment":"test lang","inode":"0"}, {"objid":"3","parenetid":"10003","path":"http:\/\/localhost\/img\/3.jpg","title":"3rd image","childcount":"0","owner":"jayjay","comment":"para amy output","inode":"0"}, {"objid":"4","parenetid":"10004","path":"http:\/\/localhost\/img\/4.jpg","title":"4th image","childcount":"0","owner":"jhim","comment":"yeah boy","inode":"0"}]
how can handle them on template? chk_db.xml
{% x in ????%} <myphotos> <objid>{{x.objid}}</objid> ... <inode>{{x.inode}}</inode> </myphotos> {% else %} <data>no data found</data> {% endfor %}
thanks...
you should git array name. rewrite $app->render
part way:
return $app->render('chkdb.xml', ['photos' => $oarray]);
and write in template:
{% x in photos %}
Comments
Post a Comment