【发布时间】:2014-07-17 08:06:55
【问题描述】:
我正在尝试合并 2 个数组的内容,然后使用 usort 来获取查看次数最多的帖子。
尝试使用 usort 对数组的内容进行排序。
我收到以下错误:
("Notice: Undefined property: Acme\DemoBundle\Entity\Article::$getViews in /.../PageController.php line 15")
谁能指出我做错了什么?
控制器内部的排序功能
private static function popularSort($articles, $posts, $articles2, $posts2)
{
return $articles->getViews() == $posts->getViews() ? 0 : ( $articles->getViews() < $posts->getViews()) ? 1: -1;
}
侧边栏操作
$articles = $this->getDoctrine()->getRepository('AcmeDemoBundle:Article')
->getArticles();
$posts = $this->getDoctrine()->getRepository('AcmeDemoBundle:Post')
->getPosts();
$popular = array_merge($articles, $posts);
usort($popular, array($this, 'popularSort'));
【问题讨论】: