Dropdown select list in CakePHP

前端 未结 10 963
一个人的身影
一个人的身影 2020-12-15 11:59

Does anybody know how to select the contents of one take from a different view in CakePHP?

I have a take itemgroups that has 2 fields ID an

10条回答
  •  Happy的楠姐
    2020-12-15 12:32

    This is the right solution in my opinion: of choices from column SET or ENUM type

    * 
    * @param string $sColumn - col name
    * @param string $sTable - if use other table as Model
    * @return array 
    */
    function fGetArrayFromSQLSet($sColumn, $sTable=null) {
    
        # Pokud neni urcena tabulka, pouzij tabulku modelu
        if( !$sTable ) {
            $sTable= $this->useTable;
        }
    
        # Nacti nastaveni daneho pole dane tabulky
        $tmpHlaseno=$this->query("SELECT COLUMN_TYPE
                        FROM information_schema.columns
                        WHERE TABLE_NAME = '$sTable'
                            AND COLUMN_NAME = '$sColumn'
            "); //db($tmpHlaseno);
        $tmpList= $tmpHlaseno[0]['columns']['COLUMN_TYPE']; 
    
        # Ziskej hodnoty z nastaveni a uloz je do pole
        $sTmp= str_replace(')', '', str_replace('set(', '', str_replace('enum(', '', $tmpList)));
        $aTmp= explode(',', str_replace("'", '', $sTmp));
        foreach( $aTmp as $value ) {
            $aSetList[$value]= $value;
        }   //db($aSetList);
    
        return $aSetList;   
    }       // END of fGetArrayFromSQLSet 
    

提交回复
热议问题