Thrace数据网格实现jqGrid:Doctrine不会触发查询

I am using Symfony, doctrine ORM, SQL Server on a Linux machine. I am trying to implement Thrace Data Grid as on https://github.com/thrace-project/datagrid-bundle. I followed the steps as they are. Here is my code: index.html.twig

{% extends "::base.html.twig" %}
{% block stylesheets %}

<link rel="stylesheet" type="text/css" media="screen" href="{{ asset('bundles/productorderlookup/css/ui-lightness/jquery-ui.css') }}" />
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset('bundles/productorderlookup/css/ui.jqgrid.css') }}" />

{% endblock %}


{% block javascripts %}
    {{ parent() }}

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="{{ asset('bundles/productorderlookup/js/init-datagrid.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/productorderlookup/js/i18n/grid.locale-en.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/productorderlookup/js/jquery.jqGrid.src.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/thracedatagrid/js/init-datagrid.js') }}" type="text/javascript"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/i18n/jquery-ui-i18n.min.js"></script>

{% endblock %}

{% block body %}
<div>{{ thrace_datagrid('user_management') }}</div>
{% endblock %}

UserManagementBuilder.php

namespace ProductOrder\UserOrderBundle;

use Doctrine\ORM\EntityManager;

use Symfony\Component\Routing\RouterInterface;

use Symfony\Component\Translation\TranslatorInterface;

use Thrace\DataGridBundle\DataGrid\DataGridFactoryInterface;

class UserManagementBuilder

{

const IDENTIFIER = 'user_management';

protected $factory;

protected $translator;

protected $router;

protected $em;


public function __construct (DataGridFactoryInterface $factory, TranslatorInterface $translator, RouterInterface $router,
                             EntityManager $em)
{
    $this->factory = $factory;
    $this->translator = $translator;
    $this->router = $router;
    $this->em = $em;
}

public function build ()
{

    $dataGrid = $this->factory->createDataGrid(self::IDENTIFIER);
    $dataGrid
        ->setCaption($this->translator->trans('user_management_datagrid.caption'))
        ->setColNames(array(
            $this->translator->trans('column.firstName'),
            $this->translator->trans('column.lastName'),
            $this->translator->trans('column.enabled'),
        ))
        ->setColModel(array(
            array(
                'name' => 'firstName', 'index' => 'u.firstName', 'width' => 200,
                'align' => 'left', 'sortable' => true, 'search' => true,
            ),
            array(
                'name' => 'lastName', 'index' => 'u.lastName', 'width' => 200,
                'align' => 'left', 'sortable' => true, 'search' => true,
            ),
            array(
                'name' => 'enabled', 'index' => 'u.enabled', 'width' => 30,
                'align' => 'left', 'sortable' => true, 'search' => true,
                'formatter' => 'checkbox', 'stype' => 'select',
                'searchoptions' => array(
                    'value' => array(
                        1 => 'enable',
                        0 => 'disabled',
                    )
                )
            ),
        ))
        ->setQueryBuilder($this->getQueryBuilder())
        ->enableSearchButton(true)
    ;

    return $dataGrid;
}


protected function getQueryBuilder()
{
    $qb = $this->em->getRepository('ProductOrderUserOrderBundle:User')->createQueryBuilder('u');
    $qb
        ->select('u.id, u.firstName, u.lastName, u.enabled')
        ->groupBy('u.id')
    ;


    return $qb;
    }
}

DefaultController.php

namespace ProductOrder\UserOrderBundle\Controller;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Symfony\Component\Httpfoundation\Request;


class DefaultController extends Controller
{
    public function indexAction()
    {
        /** @var \Thrace\DataGridBundle\DataGrid\DataGridInterface */
        $userManagementDataGrid = $this->container->get('thrace_data_grid.provider')->get('user_management');
        return $this->render('ProductOrderUserOrderBundle:Default:index.html.twig',array(
            'userManagementDataGrid' => $userManagementDataGrid,
        ));
    }
}

Entity class User.php

namespace ProductOrder\UserOrderBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;

use Doctrine\ORM\Mapping as ORM;

/**
 *  * @ORM\Table(name="TSOFT_LEARN.dbo.User")
 * @ORM\Entity
 */
class User
{
    /**
     * @var integer
     *
     * @ORM\Id @ORM\Column(name="id", type="integer")
     *
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="firstName", type="string", length=255, nullable=true, unique=false)
     */
protected $firstName;

/**
 * @var string
 *
 * @ORM\Column(name="lastName", type="string", length=255, nullable=true, unique=false)
 */
protected $lastName;

/**
 * @var boolean
 *
 * @ORM\Column(name="enabled", type="boolean")
 */
protected $enabled = false;


public function __construct()
{

}

public function getId()
{
    return $this->id;
}

public function setFirstName($firstName)
{
    $this->firstName = $firstName;
}

public function getFistName()
{
    return $this->firstName;
}

public function setLastName($lastName)
{
    $this->lastName = $lastName;
}

public function getLastName()
{
    return $this->lastName;
}

public function setEnabled($enabled)
{
    $this->enabled = $enabled;
}

public function isEnabled()
{
    return $this->enabled;
}



}

The page loads fine but on the Symfony toolbar it says, there was no query fired.

Apologies if I gave too much of code.

EDIT: Upon printing the getDQL code I got SELECT u.id, u.firstName, u.lastName, u FROM AppBundle\UserPoBundle\Entity\User u GROUP BY u.id

But on my doctrine debug window I still get no queries.

1个回答



当Doctrine连接到SQL Server时,显然存在一个错误。 当我将同一个项目连接到PostgreSQL服务器时,一切正常。 </ p>

更新:</ strong>该错误不适用于Doctrine。 当我将普通的Doctrine与纯SQL连接而没有任何datagrid包时,奇怪的别名就消失了。 但是,如果我使用任何捆绑包,问题仍然存在。</ p>

已解决:</ strong>我知道错误会变得非常简单。 当我创建User实体时,我给出的表名是 [TSOFT_LEARN]。[dbo]。[User] </ code>。 Doctrine以某种方式接受了这个名称并将其转换为“ [0 _ </ code>”一旦我摆脱了那些“ [] </ code>”一切正常。</ p>
</ div >

展开原文

原文

Apparently there is a bug in Doctrine when its connecting to SQL Server. When I connected the same project to a PostgreSQL Server, everything worked fine.

UPDATE: The bug is not with Doctrine. When I connect plain Doctrine with plain SQL without any datagrid bundles the weird alias is gone. But if I use any of the bundles, the problem persists.

SOLVED: I knew the bug was going to be something so simple. When I created the User entity, the table name I gave was [TSOFT_LEARN].[dbo].[User]. Doctrine somehow took that name and converted it to "[0_" Once I got rid of those "[]" everything worked fine.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐