标签: doctrine-orm

存储波兰字符utf8 doctrine 2 PHP,MySQL,Zend Framework

我有一个使用Zend Framework编写的CMS应用程序,允许您翻译内容.这适用于德语和法语字符,但正在与波兰语挣扎,我已正确设置数据库和连接(据我所知)但我仍然得到垃圾存储并返回波兰语.数据库是utf8_general_ci,字段也是.Doctrine connection params:resources.entityManager.connection.charset ="utf8"resources.entityManager.connection.default.parameters.driverOptions.1002 ="SET NAMES'UTF8'"

发布翻译的数据库表单的页面有:header('Content-type:text/html; charset = utf-8'); (在顶部)[meta http-equiv ="Content-Type"content ="text/html; charset = utf8"/](在head标签中)

我对保存到数据库的字符串没有额外的编码(doctrine 2):

 $cn->setContent($pageForm->getValue($field));
Run Code Online (Sandbox Code Playgroud)

所以,法国人和德国人对此很满意,但是下面的波兰语:specjalisty wprodukcjazawieszeń,szybkość

商店和视图:specjalisty wprodukcjazawieszeÅ",szybkoÅ>ć

我正在与这个圈子围成一圈,所以任何想法都会非常感激.

php mysql zend-framework doctrine-orm

0
推荐指数
1
解决办法
2539
查看次数

在MySQL中不使用GROUP获取"#1111 - 无效使用组功能"

    $qb = $this->createQueryBuilder('t');

    return $qb
        ->join('t.customers', 'c')
        ->where($qb->expr()->eq('t.user', $user->getId()))
        ->andWhere($qb->expr()->gt($qb->expr()->count('c'), 0))
        ->orderBy('t.name')->getQuery()->getResult();
Run Code Online (Sandbox Code Playgroud)

上面的查询(Doctrine2生成一个)给了我这个错误:

#1111 - Invalid use of group function

但奇怪的是我没有使用GROUP BY.非常感谢任何帮助,谢谢.

SELECT t0_.id AS id0,
       t0_.slug AS slug1,
       t0_.name AS name2,
       t0_.description AS description3,
       t0_.user_id AS user_id4
FROM tag t0_ 
    INNER JOIN customers_tags c2_ ON t0_.id = c2_.tag_id
        INNER JOIN customer c1_ ON c1_.id = c2_.customer_id
WHERE t0_.user_id = 1 AND COUNT(c1_.id) > 0
ORDER BY t0_.name ASC
Run Code Online (Sandbox Code Playgroud)

mysql sql doctrine doctrine-orm

0
推荐指数
1
解决办法
3059
查看次数

Doctrine2 - 如何限制@OneToMany映射大小?

我想知道是否有任何方法可以@OneToMany在Doctrine2 中设置关系大小的约束.

假设我有2个课程:UserToy:

class User{
    ...
    /**
     * @OneToMany(targetEntity="Toy", mappedBy="user")
     */
    public $toys;
    ...
}
class Toy{
    ...
    /**
     * @ManyToOne(targetEntity="User", inversedBy="toys")
     */
    public $user;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想强迫每个用户最多拥有3个玩具.你知道是否有办法通过使用任何Doctrine2注释来实现这一点?

如果通过注释无法实现,你会怎么做?

谢谢!

entity-relationship one-to-many symfony doctrine-orm

0
推荐指数
1
解决办法
1359
查看次数

Doctrine2:未定义的索引

当我尝试执行此DQL查询时:

SELECT r, s FROM Rule r
JOIN r.splash_page s
WHERE r.active = 1
Run Code Online (Sandbox Code Playgroud)

我想要做的只是加入两个实体,我得到这个错误:

Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 110
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Notice: Undefined index: rules in C:\xampp\htdocs\excap\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php on line 428
Run Code Online (Sandbox Code Playgroud)

这些是我的Entity文件的一部分,我在其中声明它们之间的关系:

// Rule.php 
/**
 *
 * @var type 
 * @ManyToOne(targetEntity="SplashPage", inversedBy="rules")
 */
protected $splash_page;
Run Code Online (Sandbox Code Playgroud)
// SplashPage.php
/**
 *
 * @var …
Run Code Online (Sandbox Code Playgroud)

php doctrine doctrine-orm

0
推荐指数
1
解决办法
3316
查看次数

Doctrine - 根据列值从许多结果中获取行或行

我正在使用一对多关系的学说,其中每个用户实体都有许多帖子实体.所以我有一个像这样的学说查询

$em = $this->getDoctrine()->getManager();

$query = $em->createQuery(
   'SELECT u, p FROM MYUserBundle:User u
   JOIN u.post p'
);
Run Code Online (Sandbox Code Playgroud)

然后,我可以获得这样的用户帖子

foreach($query->getResult() as $user){

   //a bunch of posts related to this user
   $posts = $user->getPosts();
}
Run Code Online (Sandbox Code Playgroud)

为方便起见,我想创建一个API,允许我根据列值从这个$ posts对象中获取特定帖子或帖子,而不使用更多查询.所以例如我有一个名为post_slug的列,所以我想能够说

$posts = $user->getPosts();
$post = $posts->findBySlug('my_slug');

//or something along those lines...
Run Code Online (Sandbox Code Playgroud)

这可以通过$ posts对象或Post实体类完成吗?

symfony doctrine-orm

0
推荐指数
1
解决办法
2540
查看次数

Symfony/Doctrine:"可捕获的致命错误:当持久化时,类<type>的对象无法转换为字符串"

symfony2应用程序具有一个Job具有类型属性的实体WebSite.

没有其他属性或方法的简化表示:

/**
 * @ORM\Entity
 * @ORM\Table(name="Job")
 */
class Job
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * @ORM\Column(type="integer", name="website_id", nullable=false)
     * @ORM\ManyToOne(targetEntity="Example\ExampleBundle\Entity\WebSite")
     */
    protected $website;
}
Run Code Online (Sandbox Code Playgroud)

Symfony/Doctrine试图website在持久化时将属性转换为字符串,从而导致错误:

可捕获的致命错误:类的对象示例\ ExampleBundle\Entity\WebSite无法转换为/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php第131行中的字符串

我相信上面的@ORM\Column注释表示website属性是一个整数.我不明白为什么Symfony/Doctrine希望尝试将website属性转换为字符串.

我试图解决此问题的非理想解决方法:

  • 添加__toString()方法WebSite,返回id属性的字符串表示,导致正确的值最终在Job.website_id数据域中结束; 这种解决方法是不切实际的,因为我将来需要__toString()在应用程序的其他地方提供字符串.

  • @ORM\Columnwebsite属性中删除注释; 这导致所有未来差异生成的迁移(php app/console doctrine:migrations:diff)删除相关数据库字段的"not null"方面.

我是否应对上述注释做出任何更改,以通知Symfony/Doctrine 在持久化时调用获取所需内容的getId()方法WebSite?我可以做出任何改变WebSite来实现同样的目标吗?

需要进行哪些更改才能确保上述注释可以保留在原位,以便Doctrine最终调用WebSite.getId()以获取持久存在时所需的内容,而不是尝试将对象强制转换为字符串?

annotations doctrine-orm symfony-2.1

0
推荐指数
1
解决办法
7512
查看次数

无法在symfony2控制器中获取当前登录的用户

我在控制器中有这个代码

public function newAction()
    {
$em = $this->getDoctrine()->getEntityManager();
$user = $this->container->get('security.context')->getToken()->getUser();
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

致命错误:在第86行的/home/xxxxx/Acme/UserBundle/Controller/UserController.php中的非对象上调用成员函数getUser()

php symfony doctrine-orm

0
推荐指数
1
解决办法
1854
查看次数

Doctrine - PostgreSQL - 表/字段名称中的大写和空格

使用空格和大写字段/表名称的Doctrine 2.3和PostgreSQL存在问题

示例:(是的,我们正在努力从此迁移)

SELECT "Field Name"
FROM "Table Name"
Run Code Online (Sandbox Code Playgroud)

我们也有两种格式的混合

SELECT "Field Name", another_field_name
FROM "Table Name", another_table_name
Run Code Online (Sandbox Code Playgroud)

使用doctrine时,我收到了PDOException.在查看错误时,我发现在包含大写和空格的Fields/Tables(名称)周围没有双引号.

有修复吗?解决方法?

这是Doctrine正在产生的一个例子

SELECT t0.TheId AS theid1, t0.Name AS name2, t0.User AS user3
FROM The Table t0 
WHERE t0.TheId = 1234
Run Code Online (Sandbox Code Playgroud)

这就是我需要的方式

SELECT t0."TheId" AS theid1, t0."Name" AS name2, t0."User" AS user3
FROM "The Table" t0 
WHERE t0."TheId" = 1234
Run Code Online (Sandbox Code Playgroud)

php sql postgresql pdo doctrine-orm

0
推荐指数
1
解决办法
2220
查看次数

尝试运行doctrine命令时"em未定义错误"

我刚刚设置了一个ZF2项目并为Doctrine2配置了所有项目而没有问题.它工作,现在只是给我一个错误,因为它找不到我想要查询的数据库表.

实体也正确设置,全部按照http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/

所以想使用CLI来创建表等,但是在运行任何CLI命令时我都会得到

[InvalidArgumentException]       
The helper "em" is not defined.
Run Code Online (Sandbox Code Playgroud)

我正在使用的命令

php doctrine.php orm:schema-tool:update --dump-sql
Run Code Online (Sandbox Code Playgroud)

我从文件夹运行doctrine.php

/Library/WebServer/Documents/zf2-Skel-NewProj1/vendor/bin
Run Code Online (Sandbox Code Playgroud)

现在,如果我将CLI用于我的一个ZF1.11项目,它可以正常工作.

为了实现这一点,我必须编辑位于其下的cli-config.php文件

/Library/WebServer/Documents/zf2-Skel-NewProj1/vendor/doctrine/orm/tools
Run Code Online (Sandbox Code Playgroud)

该文件的内容是:

<?php

require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();

$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);

$config->setProxyDir(__DIR__ …
Run Code Online (Sandbox Code Playgroud)

configuration zend-framework command-line-interface doctrine-orm

0
推荐指数
1
解决办法
3142
查看次数

具有Doctrine支持的ERD建模工具

我正在寻找一个可以用于ER建模的免费或付费软件应用程序.

由于我主要使用Symfony2/Doctrine开发应用程序,有没有人知道有Doctrine支持的软件?

database-design erd symfony doctrine-orm

0
推荐指数
1
解决办法
4295
查看次数