Zend Framework: How to concatenate two columns and still use fetchPairs()?

后端 未结 2 1005
我寻月下人不归
我寻月下人不归 2021-01-21 04:43

I have a form with a select element that I need to populate with values from a database. Specifically, the name and id of the current users. The fetchPairs() functi

2条回答
  •  心在旅途
    2021-01-21 05:18

    protected function _getSelectOptions()
    {
        $db     = Zend_Db_Table::getDefaultAdapter();
        $select = $db->select()->from('users', array(
            'id',
            'name' => new Zend_Db_Expr("CONCAT(first_name, ' ', lastname)"),
        ));
    
        return $db->fetchPairs($select);
    }
    

提交回复
热议问题