我有一个要按字母顺序排序的项目列表,以下是我的代码:

public function indexAction()
{
    $this->authoriseUser();
    $this->view->assign('title', 'Clubs');
    $this->view->headTitle($this->view->title, 'PREPEND');
    $clubs = new Application_Model_DbTable_Clubs();
    $this->view->clubs = $clubs->fetchAll();
    $select = $clubs->select();
    $select->order('club_name ASC');
}


怎么了?因为它不起作用..

谢谢

最佳答案

您需要将选择对象传递给fetchAll方法

public function indexAction()
{
    $this->authoriseUser();
    $this->view->assign('title', 'Clubs');
    $this->view->headTitle($this->view->title, 'PREPEND');
    $clubs = new Application_Model_DbTable_Clubs();
    $select = $clubs->select()
        ->order('club_name ASC');
    $this->view->clubs = $clubs->fetchAll($select);
}

关于zend-framework - Zend框架ORDER BY,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10422173/

10-10 01:04