php
  • sugarcrm
  • 2017-03-08 45 views 0 likes 
    0

    這是我的代碼:SugarCRM的下拉值排序

    custom/Extension/application/Ext/Utils/ or custom/include/custom_utils.php

    <?php 
    
    function getActiveReleases() 
    { 
        $query = "SELECT id, name FROM releases where deleted=0 and status='Active' order by list_order asc"; 
        $result = $GLOBALS['db']->query($query, false); 
    
        $list = array(); 
        $list['']=''; 
        while (($row = $GLOBALS['db']->fetchByAssoc($result)) != null) { 
         $list[$row['id']] = $row['name']; 
        } 
    
        return $list; 
    } 
    
    unset($dictionary['MODULENAME']['fields']['FIELDNAME']['options']); 
    $dictionary['MODULENAME']['fields']['FIELDNAME']['function'] = 'getActiveReleases'; 
    

    Refrence From here

    我做同樣的事情在我的代碼,它工作正常,除了整理:ORDER BY list_order asc
    下拉應按順序排列如下:order by list_order asc
    但糖覆蓋它並按下拉列表的關鍵值對下拉菜單進行排序:id
    我想鍵值爲ID但排序應該是這樣的:order by list_order asc

    我在谷歌搜索,但我並沒有發現任何辦法做到這一點,所以我張貼了這個問題。通過索引數組

    $list[$row['id']] = $row['name']; 
    

    回答

    0

    替換此

    $arrayIndex = 0; 
    while (($row = $GLOBALS['db']->fetchByAssoc($result)) != null) { 
        $list[$arrayIndex] = $row['name']; 
        $arrayIndex++; 
    } 
    

    它不是sugarcms,它是關於PHP本身

    ,而您提供的$row['id']作爲按性質排序的數組鍵,

    PHP將這個變量的值

    的順序求助於它把這個作爲一個簡單的例子:https://3v4l.org/8HjFB,我希望這使得

    +0

    但是我需要那個鑰匙,我在其他地方也使用那個鑰匙。 –

    +0

    作爲一個單獨的元素添加這個怎麼樣?例如'$ list [$ arrayIndex] = $ row'。 – hassan

    +0

    我不明白 –

    0

    這個怎麼樣您while語句後,更清楚嗎?

    asort($list); 
    return $list; 
    

    documentation

    此函數對一個數組,使得數組的索引保持與它們相關聯的數組元素的 相關性。在排序關聯數組時,主要用於 ,其中實際元素 的順序很重要。

    +0

    排序不是在糖工作 –

    +0

    不工作如何?即使在返回之前添加了asort函數,它也沒有對它們進行排序? – Reisclef

    +0

    添加它時出現錯誤。 –

    相關問題