Я пытаюсь объединить содержимое двух массивов, а затем использовать 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'));
Подробнее здесь: https://stackoverflow.com/questions/247 ... controller