How can i override easyAdminBundle Controller

2.8k views Asked by At

I want to know how to override an EasyAdminBundle controller. Actually, I want to write some custom query from the database and I don't want to use dqlFilter.

Following is my config.yml file.

 easy_admin:
    site_name: 'site mame .'
    entities:
        User:
            class: EmployeeBundle\Entity\EmployeeLogin
            controller: EmployeeBundle\Controller\UserController
            form:
                fields: ['id', {property : 'userName', label : 'Users'}, {property: 'status', type:'choice', type_options: {choices: {'Active':'1', 'Deactive':'0'}}}]
            new:
                title: 'Add Login'
                form_options: { validation_groups: ['Default', 'EmployeeLogin'] }
                fields: ['-id']
            edit:
                title:  'Edit Login Details'
                form_options: { validation_groups: ['Default'] }
            label: 'Employees'
            list:
                title: "%%entity_label%% customers"
                help: 'The list view overrides the global help message'
                fields: ['id', {property : 'userName', label : 'Users'}, {property: 'status', type: 'boolean'}, {property : 'lastLogin',format: 'D j-n-Y, h:i:s'}]

And this is my UserController where I extend BaseAdminController please let me know how can I customize the query from repository or within a Controller

namespace EmployeeBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
use Symfony\Component\HttpFoundation\Request;

class UserController extends BaseAdminController
{
    public function listUserAction()
    {

    }
}
1

There are 1 answers

0
shazz Abbasi On

I did this and it worked hope it will be helpful someone else:

public function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
      {
          $response =  parent::createListQueryBuilder('EmployeeLogin, EmployeeMaster', $sortDirection, $sortField, $dqlFilter); // TODO: Change the autogenerated stub


          $response->join('entity.userId','emp');
          $response->andWhere('emp.lastName = :role')->setParameter('role', 'sagir');

           return $response;