donglao9606 2015-05-05 13:25
浏览 110
已采纳

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条回答

  • dongzhansong5785 2015-05-06 12:33
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号