草庐IT

Doctrine_Query

全部标签

php - 未捕获的 PHP 异常 Doctrine\ORM\ORMException : "Unknown Entity namespace alias ' AppBundle'.“

我刚刚开始了我的第一个composer项目,想为它设置数据库和类。但是我被卡住了。我在prod.log中收到上述错误我在这里遵循了本教程:http://symfony.com/doc/current/book/doctrine.html我创建了数据库phpbin/consoledoctrine:database:create然后想创建一个实体phpbin/consoledoctrine:generate:entity当询问实体快捷方式名称时,我输入了AppBundle:Product然后创建数据库字段等。我收到了这条消息EntitygenerationGeneratingentityc

php - Doctrine 不映射来自 FOSUserBundle 用户类的字段

当从FOSUserBundle继承User-Class时,doctrine将无法识别基User类的继承属性。只有我自己的类的属性才会用于创建/更新数据库模式。这是config.yml:配置文件:doctrine:orm:auto_generate_proxy_classes:"%kernel.debug%"naming_strategy:doctrine.orm.naming_strategy.underscoreauto_mapping:truemappings:FOSUserBundle:~AppBundle:~fos_user:db_driver:ormfirewall_name

php - Symfony/Doctrine - createQueryBuilder orderBy

我有一个“团队”实体,其属性为“预算”。我只想打印团队属性,我希望预算最高的团队出现在第一位、第二位、第三位...(DESC)。但是使用这段代码,它不起作用,我不明白为什么。indexAction(Controller)$em=$this->getDoctrine()->getManager();$teams=$em->getRepository('FootballBundle:Team')->getAllTeamsSortedByDescBudget();return$this->render('FootballBundle:Default:index.html.twig',arra

php - Symfony/Doctrine 中的动态数据库和模式创建

我想在静态数据库中存储数据库连接。根据需要,我想创建一个新数据库,将凭据存储在我的静态数据库中,然后根据现有实体在新数据库中创建模式。我知道如何使用symfony的命令行工具来做到这一点。我的目标是让它在服务中工作。我查看了Doctrine文档并尝试让一些东西起作用:$conn=$this->getDoctrine()->getConnection()->getSchemaManager()->createDatabase($dbname);$isDevMode=true;$config=Setup::createAnnotationMetadataConfiguration(arra

php - Doctrine——选择所有字段并按其中一个分组

我正在尝试使用doctrine创建一个查询,它基本上应该类似于SQL中的查询:SELECTp.*FROMsome_tabelASpGROUPBYp.type;所以我最终得到了这个,因为这是我发现的最接近的记录:privatefunctiongetAll(){//$this->em=>EntityManagerreturn$this->em->createQueryBuilder()->select('p')->from('AppBundle:Robots','p')->groupBy('p.type')->getQuery()->getResult(Query::HYDRATE_ARR

php - Doctrine 2.5 意外的关联获取行为 [Symfony 3]

我有3个实体以这种方式关联:别担心,我已经使用注释设置了关联,但我认为以下组合会更轻量/更干净以暴露我的问题Post@ORM\ManyToOne(targetEntity="User",fetch="EAGER")-authorUser@ORM\OneToOne(targetEntity="Vip",mappedBy="user",fetch="EAGER")-vipVip#NoticethattheprimarykeyofvipisaforeignkeyonUserprimary@ORM\id@ORM\OneToOne(targetEntity="User",inversedBy="

php - Laravel Eloquent : dynamically adding parameters to advanced query

我在Laravel中有一个带有字母的数组,例如$letters=array("E","T","R");我现在想将这些添加到高级查询中,以便它最终像这样:Table::where('status',1)->where(function($q){$q->where('city','like',"E%")->orWhere('city','like',"T%")->orWhere('city','like',"R%");});但我不确定如何遍历这些字母。像这样的事情失败了:Table::where('status',1)->where(function($q){foreach($letter

php - 调用未定义的方法 Illuminate\Database\Query\Builder::post()

我在使用查询构建器时遇到问题,在路由文件中使用post()时会出现未定义的方法错误。一般我用的是returnofUser::find($id)->post;但是当我将post作为函数调用时,它不起作用并给我:CalltoundefinedmethodIlluminate\Database\Query\Builder::post()用户模型hasOne('App\Post');}}路线Route::get('/',function(){returnview('welcome');});Route::get('/user/{id}/post',function($id){returnUse

php - Laravel Query Builder 其间

我构建了一个搜索表单,它将从数据选择器中插入日期的数据库中选择标记。这很好用,但是,当我添加时间时,我得到错误。我重建了一个类似这样的查询:$datefrom=$request->input('datefrom');$dateto=$request->input('dateto');$timefrom=$request->input('timefrom');$timfrom=$timefrom.':00';$timeto=$request->input('timeto');$timto=$timeto.':00';$type=$request->input('type');$maps=

php - Woocommerce wp_query 按 ID 获取订单

我正在尝试生成订单数据的简单输出。第一步是WP_QUery(可能)所以我写了这段代码;$args=array('post_type'=>'shop_order','posts_per_page'=>-1,'post_status'=>'any',//'p'=>$post_id,);$order_query=newWP_Query($args);while($order_query->have_posts()):$order_query->the_post();echothe_ID();echo':';the_title();echo'';endwhile;它要求产品列出所有订单,如果我