Tôi đã mã hóa một trang hiển thị tất cả quản trị viên của hệ thống. Những gì tôi muốn làm là tùy chỉnh truy vấn của tôi để nó sẽ loại trừ người dùng được xác thực hiện tại khỏi danh sách.
Bây giờ tôi biết tôi có thể lấy user_id
từ bộ điều khiển và chuyển nó vào kho lưu trữ thực thể, nhưng tôi đã tự hỏi liệu có cách nào truy cập trực tiếp thông qua Entity Repository không?Symfony2 nhận id người dùng trong kho lưu trữ thực thể
Ví dụ:
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
class AdminUserRepository extends EntityRepository implements UserProviderInterface
{
public function getAdmins($int = 10, $offset = 0, array $orderBy = array('admin_id', 'asc')){
$admin_id = fetch the admin id ?;
$query = $this->createQueryBuilder('admins')
->where("admins.admin_id != '".$admin_id."'")
->orderBy('admins.'.$orderBy[0], $orderBy[1])
->setFirstResult($offset)
->setMaxResults($int)
->getQuery()
->getResult();
return $query;
}
}
Tôi đã cập nhật câu hỏi của mình. Tôi biết tôi có thể làm điều đó theo cách bạn đang nói, nhưng tôi đang tìm kiếm nếu nó có thể được thực hiện trong 'EntityRepository' chính nó. – tftd
/cập nhật ... hy vọng điều đó sẽ hữu ích. –
Tôi đã suy nghĩ cùng một điều nhưng đó là loại hợp lý (đối với tôi) để có thể truy cập dữ liệu người dùng xác thực từ bên trong một kho lưu trữ. Cảm ơn bạn đã giúp đỡ :) – tftd