php - 使用 zend view helper 的下拉菜单

标签 php mysql zend-framework drop-down-menu

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

这是我的 View 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 "]) 字符串|数组 $name: 如果是字符串,则为元素名称。如果是数组,则忽略所有其他参数,并提取数组元素代替添加的参数。

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

最佳答案

将其更改为:

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

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

return $options;

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

关于php - 使用 zend view helper 的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12749434/

相关文章:

php - 多次接收 Paypal IPN 响应

mysql - SQL:每个 ID 创建超过 1 个值的查询

php - 在中型企业网站中使用 Zend Framework 是个好主意吗?

php - 如何使用 javascript 创建一个简单的按钮来调用 zend 框架中的 zend 操作?

jquery - ZFdebug Jquery干扰

php - 从字符串在调用函数中创建局部变量

php - 静态变量设置为 null,然后使用 if 语句检查该变量是否为 null

php - 基于规则的求职者分类算法

c# - 登录表单错误。 IF 条件不能正常工作

MySQL 日期比较过滤器