我试图获得公司名称ORDER BY ASC或DECS但我厌倦了似乎没有工作......我是Zend Framework的新手并继承了这个应用程序,现在不得不对它进行更新,我一直在阅读Zend他们网站上的文档...任何反馈,例子将不胜感激
这是在我的模型中
class Application_Model_DbTable_X2payUsers extends
Zend_Db_Table_Abstract
{
protected $_name = 'users';
protected $_primary = 'id';
public function getAllUsers(){
$users = $this->fetchAll(Zend_db::FETCH_OBJ);
// $db->setFetchMode(Zend_Db::FETCH_OBJ);
// $users = $db->fetchAll('SELECT * FROM users ORDER BY DECS');
$result = array();
foreach($users as $user){
$result [$user->id]= $user->company_name;
}
return $result;
}
这是我使用
的交易过滤器表格 class Application_Form_TransactionFilter extends Zend_Form
{
private $_company = '';
public function __construct($company = '') {
$this->_company = $company;
return parent::__construct();
}
public function init()
{
$this->setName('transaction-filter');
$this->setAction('');
$this->setMethod('GET');
$users_table = new Application_Model_DbTable_X2Users();
$users = $users_table->getAllUsers();
// ->orderby('company_name ASC');
$company = new Zend_Form_Element_Select('company');
$company->addFilter('StripTags')
->setAttrib('class', 'form-control')
->addValidator('NotEmpty')
->setRequired(true)
->addFilter('StringTrim')
->removeDecorator('label')
->removeDecorator('htmlTag')
->removeDecorator('Errors');
$company->addMultiOptions(
array(''=>'-- Select Company --')
);
$company->addMultiOptions($users);
$company->getValidator('NotEmpty')->setMessage('Please select a company');
$company->setValue($this->_company);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('class', 'btn btn-default')
->setLabel('Submit')
->removeDecorator('DtDdWrapper')
->removeDecorator('label')
->removeDecorator('htmlTag');
$this->setDecorators(array(array('ViewScript',
array('viewScript' => '_transaction_filter.phtml'))));
$this->addElements(array($company, $submit));
}
}
这是交易文件中的代码
<?= $this->filter ?>
答案 0 :(得分:0)
您正在使用 Zend_Db_Table_Abstract 的 fetchAll 方法,第一个参数可以是:
第二个参数是订单,可以是订单sql,例如&#34; company_name DESC&#34;或多个订单的数组,例如Twinkie 10 1 1 10 10 10 0
Banana 10 1 1 5 5 0 0
Potato 20 1 1 5 5 0 0
Protein_Shake 5 5 1 30 10 10 1
Beer 5 5 1 5 10 10 1
。想要在你的情况下使用
一种方法是:
array("company_name DESC", "id ASC")