2015-06-03 23:57



So here is my code... Which I used in my Project.

    function () use ($app){
      require_once 'lib/mysql.php';
      $dx = connect_db('MyPhotos');

      $res = $app->response();
      $res['Content-Type'] = 'application/xml';
      $view = $app->view();
      $oArray = array("Status"=> $dx.status, "code" => $dx.code);
      return $app->render('chkdb.xml', $oArray);

so i have this Array as an input to the xml template (by the way... this is json_encoded... I just use it to represent the 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 I handle them on the template? chk_db.xml

{% for x in ????%}
{% else %}
<data>No data Found</data>
{% endfor %}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dpa84373 dpa84373 6年前

    Oh man... my bad.. I found the answer to this... There is nothing wrong on my Template.. it's my bad not naming the Array I send.. Here's the corrected code..

        function () use ($app) {
            require_once 'lib/mysql.php';
            $re = getAll_photos('MyPhotos');
            $app->response()->headers->set('Content-Type', 'text/xml');
            return $app->render('myphotos_allphotos_admin.xml', array("ArrayName" => $re));

    I forgot to name the Array i send... So here i put ArrayName as the name of the $re...

    So in the template i use the..

    {% for x in ArrayName %}
    {% else %}
        Not Found
    {% endfor %}

    Hope it helps somebody else ^^,

    点赞 评论 复制链接分享
  • duanmo5724 duanmo5724 6年前

    You should git this array a name. Just rewrite $app->render part this way:

    return $app->render('chkdb.xml', ['photos' => $oArray]);

    And write in template:

    {% for x in photos %}
    点赞 评论 复制链接分享