Кемеровские программисты php общаются здесь
Anonymous
Неустранимая ошибка: невозможно использовать объект типа User\Entity\User в качестве массива.
Сообщение
Anonymous » 08 окт 2024, 13:05
Проблема в следующем:
ошибка:
Код: Выделить всё
=> Fatal error: Cannot use object of type User\Entity\User as array in ../module/User/view/user/index/index.phtml
Мой класс:
Код: Выделить всё
class IndexController extends ApplicationController
{
/**
* Store the user.
* @var \User\Entity\User
*/
protected $_user;
public function indexAction()
{
$offset = 6;
$page = $this->params()->fromQuery('page');
if (!$page) {
$page = 1;
}
$dql = "SELECT
users
FROM User\Entity\User users
GROUP BY users.id
ORDER BY " . $this->getOrderDql();
$query = $this->objectManager()
->createQuery($dql)
->setFirstResult(($page - 1) * $offset)
->setMaxResults($offset);
$users = new Paginator($query, $fetchJoinCollection = true);
$quantity = (int) ceil($users->count() / $offset);
return new ViewModel(
array(
'users' => $users,
'offset' => $offset,
'page' => $page,
'quantity' => $quantity,
'order' => $this->getOrderValue(),
)
);
}
}
Спасибо за ответы!
(текст, чтобы мой пост не был в основном кодом)
Подробнее здесь:
https://stackoverflow.com/questions/220 ... r-as-array
1728381910
Anonymous
Проблема в следующем: [code] [/code] ошибка: [code]=> Fatal error: Cannot use object of type User\Entity\User as array in ../module/User/view/user/index/index.phtml [/code] Мой класс: [code]class IndexController extends ApplicationController { /** * Store the user. * @var \User\Entity\User */ protected $_user; public function indexAction() { $offset = 6; $page = $this->params()->fromQuery('page'); if (!$page) { $page = 1; } $dql = "SELECT users FROM User\Entity\User users GROUP BY users.id ORDER BY " . $this->getOrderDql(); $query = $this->objectManager() ->createQuery($dql) ->setFirstResult(($page - 1) * $offset) ->setMaxResults($offset); $users = new Paginator($query, $fetchJoinCollection = true); $quantity = (int) ceil($users->count() / $offset); return new ViewModel( array( 'users' => $users, 'offset' => $offset, 'page' => $page, 'quantity' => $quantity, 'order' => $this->getOrderValue(), ) ); } } [/code] Спасибо за ответы! (текст, чтобы мой пост не был в основном кодом) Подробнее здесь: [url]https://stackoverflow.com/questions/22094274/fatal-error-cannot-use-object-of-type-user-entity-user-as-array[/url]
0 Ответы
13 Просмотры
Последнее сообщение Anonymous
06 фев 2025, 20:04
0 Ответы
10 Просмотры
Последнее сообщение Anonymous
07 июн 2025, 05:02
0 Ответы
13 Просмотры
Последнее сообщение Anonymous
08 ноя 2024, 07:03
0 Ответы
45 Просмотры
Последнее сообщение Anonymous
12 ноя 2024, 15:01
0 Ответы
128 Просмотры
Последнее сообщение Anonymous
18 ноя 2024, 11:10