简体   繁体   中英

dropdown menu using zend view helper

I have a dropdown menu grabbing all the flag (or call it tags) values from a database table using the zend view helper, formSelect() function but the values are displaying in an array format. I only need the flag value names themselves.

Here is the code within my view phtml file to display the drop down menu:

<td><?php echo $this->formSelect('flag_id', null, null, $this->aFlags); ?> </td>

The flag methods are in this class:

class App_Flags extends App {

public $rows = array(iPropertyID);

public function __construct() {
parent::__construct();
}

public function getPropFlags() {
$flag_tcid = 4;

$oSql = new Db_Table_Flags();
$oSelect = $oSql->select();
$oSelect->from(array('f' => 'flags'),array('value' => 'flag_name'));
$oSelect->where('flag_type_category = ?', $flag_tcid);
$rowCount = count($oSelect);

if ($rowCount > 0) {
    echo "found $rowCount rows";
}  else {
    echo 'no rows matched the query';
}

$result = $oSql->fetchAll($oSelect)->toArray();

return $result;

}

The drop down menu displays the values as follow:

   0 
    flag name 
   1  
    another flag name 
   2  
    flag name again  
   3 
    flag name here

I do not want the array keys displayed in the drop down. I only need the flag names. It seems like the first parameter in the formSelect() is being ignored b/c its pulling an array according to this:

string formSelect (string|array $name, [mixed $value = null], [array|string $attribs = null], [array $options = null], [string $listsep = "
\\n"]) string|array $name: If a string, the element name. If an array, all other parameters are ignored, and the array elements are extracted in place of added parameters.

Or it could be the way the query is setup in getPropFlags(). I'm not sure what I'm doing wrong. I have been looking at this for a while and running out of ideas. Any help would be great.

Change it to:

$result = $oSql->fetchAll($oSelect)

$options = array();
foreach($result as $k => $v) {
    $options[$v['f']] => $v['value'];
}

return $options;

Do some var_dumps to compare the arrays. You need a simple key/value pair array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM