1

我有一个下拉菜单,使用 zend 视图助手 formSelect() 函数从数据库表中获取所有标志(或称为标签)值,但这些值以数组格式显示。我只需要标志值名称本身。

这是我的视图 phtml 文件中用于显示下拉菜单的代码:

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

标志方法在此类中:

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;

}

下拉菜单显示的值如下:

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

我不希望在下拉列表中显示数组键。我只需要标志名称。似乎 formSelect() 中的第一个参数被忽略了 b/c 它根据这个拉数组:

string formSelect (string|array $name, [mixed $value = null], [array|string $attribs = null], [array $options = null], [string $listsep = "
\n"]) string|array $ name:如果是字符串,则为元素名称。如果是数组,则忽略所有其他参数,并提取数组元素以代替添加的参数。

或者它可能是在 getPropFlags() 中设置查询的方式。我不确定我做错了什么。我一直在看这个一段时间并且没有想法。任何帮助都会很棒。

4

1 回答 1

0

将其更改为:

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

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

return $options;

做一些 var_dumps 来比较数组。您需要一个简单的键/值对数组。

于 2012-10-05T17:37:31.340 回答