Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何显示zend framework数据网格数据按“排序”;日期“;默认情况下?_Php_Zend Framework_Zfdatagrid - Fatal编程技术网

Php 如何显示zend framework数据网格数据按“排序”;日期“;默认情况下?

Php 如何显示zend framework数据网格数据按“排序”;日期“;默认情况下?,php,zend-framework,zfdatagrid,Php,Zend Framework,Zfdatagrid,如何默认显示按“日期”排序的zend framework数据网格数据? 当我进入页面时,我希望看到默认情况下按时间排序的数据网格,而不在URL中获取参数,如…/order/created\u DESC/ $testimonials = new Application_Model_DbTable_Testimonials(); $source = new Bvb_Grid_Source_Zend_Table($testimonials); 谢谢 我通过将$select而不是$ob

如何默认显示按“日期”排序的zend framework数据网格数据? 当我进入页面时,我希望看到默认情况下按时间排序的数据网格,而不在URL中获取参数,如…/order/created\u DESC/

$testimonials = new Application_Model_DbTable_Testimonials();
        $source = new Bvb_Grid_Source_Zend_Table($testimonials);
谢谢

我通过将$select而不是$object传递给datagrid解决了这个问题

$testimonials = new Application_Model_DbTable_Testimonials();
        $source = new Bvb_Grid_Source_Zend_Table($testimonials);
现在是

$testimonials = new Application_Model_DbTable_Testimonials();
        $testimonials->setSortOrder('created');
        $source = new Bvb_Grid_Source_Zend_Select($testimonials->getTestimonials());

很难看到你的班级在做什么,因为你没有发布那个

但是当使用
fetchAll
()函数时,您可以做两件事:

选项1

当Grid类中存在fetchAll()调用时,可以进行以下操作:

$testimonialsTable->fetchAll(null, 'date'));
选项2

您可以在执行以下操作时,在
应用程序\u Model\u DbTable\u证明
类中重新编写
fetchAll
-方法

public function fetchRow($where = null, $order = null, $offset = null)
{
    if ($order===null) : $order='date'; endif;

    return parent::fetchAll(where, $order, $offset)
}

请注意,在最后一个示例中,fetchess始终默认按日期字段排序

这实际上不是最好的解决方案,请查看我的,它可能会对您有所帮助。我刚刚将select传递给grid,并已按日期设置了订单。