草庐IT

Doctrine_RawSql

全部标签

php - 使用 Doctrine EntityRepository 中的魔术查找方法好吗?

我在symfony框架的上下文中提问。我想知道这是否是使用魔法查找方法(如find($id)、findByField($value)等...)的好习惯。那些方法既没有返回类型也没有定义。这导致我的IDE在它们周围标记警告。此外,我必须始终在使用这些方法时标记返回值的类型,以使代码完成对这些变量起作用。作为一种解决方案,我通常在自定义存储库类中编写getter。在symfony文档中有这样的getter的例子,它重载了魔术findBy方法的变体。我对这种重载魔法查找方法也有不好的感觉,因为它有点混合了我自己的repo实现和父EntityRepository实现。所以我最终编写了使用“ge

php - 在 Symfony 中使用 Doctrine 创建表

在MySQL中创建了一个“电机”数据库后,我在Symfony中使用以下命令配置了该数据库:$phpsymfonyconfigure:database"mysql:host=localhost;dbname=motor"root在appname/config/doctrine/下,我有一个schema.yml文件。在这个文件中我定义了下表:Car:actAs:{Timestampable:~}columns:brand:{type:string(255),notnull:true}model:{type:string(255),notnull:true}version:{type:str

php - Symfony + Doctrine 与链接表的多对多关系

情况:我有3个表:Student、Address、StudentAddressLink如下注意*不是确切的yaml文件,但你明白了Student:column:id:blahblahname:blahblahAddress:column:id:~street:~StudentAddressLink:column:id:~student_id:~address_id:~relations:Student:local:student_idforeign:idAddress:local:address_idforeign:id我想从Student对象获取相关的“AddressStreet”目

php - 判断一个实体是否存在于 Doctrine 2 中的最有效方法

我正在创建注册表单并想检查电子邮件是否尚未与帐户相关联。我能看到的所有方法都将创建整个用户实体,但我只需要知道它是否存在。 最佳答案 publicfunctionisUnusedEmail($email){$em=static::$pimple['em'];$dql='SELECT1FROMApp\Model\UseruserWHEREuser.email=:email';$query=$em->createQuery($dql);$query->setParameter('email',$email);$res=$query->g

php - 运行 "No such file or directory"时的故障排除 `php app/console doctrine:schema:create`

我是Symfony2(beta4)和Doctrine的新手,当我尝试通过命令行创建数据库架构时遇到问题。这是错误:$phpapp/consoledoctrine:schema:createCreatingdatabaseschema...[PDOException]SQLSTATE[HY000][2002]Nosuchfileordirectory[ErrorException]Warning:PDO::__construct():[2002]Nosuchfileordirectory(tryingtoconnectviaunix:///var/mysql/mysql.sock)in/

php - 运行 "No such file or directory"时的故障排除 `php app/console doctrine:schema:create`

我是Symfony2(beta4)和Doctrine的新手,当我尝试通过命令行创建数据库架构时遇到问题。这是错误:$phpapp/consoledoctrine:schema:createCreatingdatabaseschema...[PDOException]SQLSTATE[HY000][2002]Nosuchfileordirectory[ErrorException]Warning:PDO::__construct():[2002]Nosuchfileordirectory(tryingtoconnectviaunix:///var/mysql/mysql.sock)in/

php - 使用 PHP Doctrine ORM 的复杂 WHERE 子句

我正在使用PHPDoctrineORM来构建我的查询。但是,我似乎不太明白如何使用DQL(DoctrineQueryLanguage)编写以下WHERE子句:WHEREname='ABC'AND(category1='X'ORcategory2='X'ORcategory3='X')ANDprice>10如何指定括号的位置?我目前的PHP代码是这样的:->where('name=?','ABC')->andWhere('category1=?','X')->orWhere('category2=?','X')->orWhere('category3=?','X')->andWhere(

php - 使用 PHP Doctrine ORM 的复杂 WHERE 子句

我正在使用PHPDoctrineORM来构建我的查询。但是,我似乎不太明白如何使用DQL(DoctrineQueryLanguage)编写以下WHERE子句:WHEREname='ABC'AND(category1='X'ORcategory2='X'ORcategory3='X')ANDprice>10如何指定括号的位置?我目前的PHP代码是这样的:->where('name=?','ABC')->andWhere('category1=?','X')->orWhere('category2=?','X')->orWhere('category3=?','X')->andWhere(

php - Doctrine2 加入 SUM

我正在尝试找出在Doctrine2中执行此操作的最佳方法。我有帐户实体,其中有一对多到交易实体。我需要对按帐户过滤的交易中的所有值求和。在SQL中是这样的:SELECTa.*,SUM(t.amount)ASbalanceFROMaccountaINNERJOINtransactiontONt.account_id=a.id方法#1:直接在实体上classAccount{//someotherdefinitions/***@OneToMany(targetEntity="Transaction",mappedBy="account")*/private$transactions;publ

php - 为什么我不能在 Doctrine 实体中使用公共(public)属性?

假设我有一个非常简单的PHPCRUD系统来管理数据库。假设它包含一个产品列表。使用DoctrineORM,我想查询数据库并查看/编辑/添加记录。根据GettingStarted手册,Whencreatingentityclasses,allofthefieldsshouldbeprotectedorprivate(notpublic),withgetterandsettermethodsforeachone(except$id).TheuseofmutatorsallowsDoctrinetohookintocallswhichmanipulatetheentitiesinwaysth