dsl36367 2018-01-31 08:24
浏览 26
已采纳

Silverstripe 3.3循环循环不获取值

Good morning,

Im struggling with a loop that is not working. I want to generate a xml file by looping through some products, 5 in my case. I've got the products in an arraylist and they show up as expected but then I want in that loop to loop through another arraylist with cars for that product. And thats where my problem is.

    <% loop $getProducts %>
        <% loop $getCars($ID) %>
            <item>$ID</item>
        <% end_loop %>
    <% end_loop %>

This is my template file with the loops im talking about. $getProducts is working, if I print the $ID in the getProducts loop its working good. But $getCars is empty and just showing < item >< /item >

The functions in the controller are those.

public function getProducts() {
    return GoogleShoppingFeed::mergeProductsAutos();
}

public function getCars($productID) {
    return GoogleShoppingFeed::getCarsByProduct($productID);
}

The function mergeProductsAutos is working fine.

public static function getCarsByProduct($productID = null) {
    if($productID) {
        switch($productID){
            case 127: 
                return self::$example1;
                break;
            case 126: 
                return self::$example2;
                break;
            case 781:
                return self::$example3;
                break;
            case 2924:
                return self::$example4;
                break;
            case 993:
                return self::$example5;
                break;
            case 5195:
                return self::$example6;
                break; 
        }
    } else {
        return false;
    }
}

This function should return the filled arrayLists, they're correctly filled so there is not the problem.

Sorry for my terrible english but I hope someone can help me! Thanks.

  • 写回答

1条回答 默认 最新

  • dsf6281 2018-01-31 08:50
    关注

    Problem solved.

        <% loop $getProducts %>
            <% loop $Up.getCars($ID) %>
                <item>$ID</item>
            <% end_loop %>
        <% end_loop %>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器