<bdo id='h6wEw'></bdo><ul id='h6wEw'></ul>

    <small id='h6wEw'></small><noframes id='h6wEw'>

    <tfoot id='h6wEw'></tfoot>
  1. <i id='h6wEw'><tr id='h6wEw'><dt id='h6wEw'><q id='h6wEw'><span id='h6wEw'><b id='h6wEw'><form id='h6wEw'><ins id='h6wEw'></ins><ul id='h6wEw'></ul><sub id='h6wEw'></sub></form><legend id='h6wEw'></legend><bdo id='h6wEw'><pre id='h6wEw'><center id='h6wEw'></center></pre></bdo></b><th id='h6wEw'></th></span></q></dt></tr></i><div id='h6wEw'><tfoot id='h6wEw'></tfoot><dl id='h6wEw'><fieldset id='h6wEw'></fieldset></dl></div>

    1. <legend id='h6wEw'><style id='h6wEw'><dir id='h6wEw'><q id='h6wEw'></q></dir></style></legend>
    2. FatalErrorException:错误:在非对象上调用成员函数 has()

      FatalErrorException: Error: Call to a member function has() on a non-object(FatalErrorException:错误:在非对象上调用成员函数 has())

        <small id='pOY9r'></small><noframes id='pOY9r'>

        <legend id='pOY9r'><style id='pOY9r'><dir id='pOY9r'><q id='pOY9r'></q></dir></style></legend>

          • <bdo id='pOY9r'></bdo><ul id='pOY9r'></ul>

          • <tfoot id='pOY9r'></tfoot>
              <tbody id='pOY9r'></tbody>
              <i id='pOY9r'><tr id='pOY9r'><dt id='pOY9r'><q id='pOY9r'><span id='pOY9r'><b id='pOY9r'><form id='pOY9r'><ins id='pOY9r'></ins><ul id='pOY9r'></ul><sub id='pOY9r'></sub></form><legend id='pOY9r'></legend><bdo id='pOY9r'><pre id='pOY9r'><center id='pOY9r'></center></pre></bdo></b><th id='pOY9r'></th></span></q></dt></tr></i><div id='pOY9r'><tfoot id='pOY9r'></tfoot><dl id='pOY9r'><fieldset id='pOY9r'></fieldset></dl></div>
              • 本文介绍了FatalErrorException:错误:在非对象上调用成员函数 has()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已经阅读了很多关于此的主题,但我似乎无法找到解决问题的方法.

                I have a read a lot of topics on this and I can't seem to find a solution to my problem.

                我觉得问题很明显,也许我只是盯着它太久了.

                I feel like the problem is obvious and maybe I have just been staring at it too long.

                错误是 FatalErrorException: Error: Call to a member function has() on a non-object in/vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 198

                The error is FatalErrorException: Error: Call to a member function has() on a non-object in /vagrant/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 198

                查看错误行,它说.

                public function getDoctrine()
                    {
                        if (!$this->container->has('doctrine')) {
                            throw new LogicException('The DoctrineBundle is not registered in your application.');
                        }
                
                        return $this->container->get('doctrine');
                    }
                

                这是我的代码...

                这是调用 DAO 控制器的主控制器

                This is the main controller that is calling the DAO Controller

                public function clickThroughAction(request $request, $hash)
                    {
                        if (isset($hash)) {
                            $dbController = $this->get('database_controller');
                            print_r($dbController->getReferralIdByHash($hash));
                            return $this->redirect($this->generateUrl('home'));
                        } else {
                            return 0;
                
                        }
                    }
                

                这是正在使用的服务.

                services:
                    database_controller:
                        class:  FuelFormBundleControllerDatabaseController
                

                这是调用数据库的 dao 控制器.

                This is the dao controller that is calling the database.

                public function getReferralIdByHash($hash)
                    {
                        $em = $this->getDoctrine()->getManager();
                        $query = $em->createQuery(
                            'Select u From FuelFormBundle:UserReferrals u WHERE u.user_hash = :hash'
                        )->setParameter('hash', $hash);
                
                        $referral = $query->getResult();
                
                        if (!$referral) {
                            throw $this->createNotFoundException(
                                'No product referral found'
                            );
                            $logger = $this->get('logger');
                            $logger->info('I just got the logger');
                            $logger->crit('An error occurred, hash for referrals is not recognized. current hash is: ' . $hash . " .");
                            return $this->redirect($this->generateUrl('home'));
                        }
                
                        $clickThroughCount = $referral[0]->getClickThrough();
                        $referral[0]->setClickThrough($clickThroughCount + 1);
                        $em->flush();
                        return $referral;
                    }
                

                我认为问题在于不存在教义容器,这就是我遇到问题的原因.我不知道如何解决这个问题.

                I think the problem is that the doctrine container is not present which is why I am having issues. I am not sure how to solve this.

                感谢任何帮助.谢谢!

                编辑

                好的,这就是我所做的更改.

                Ok so here is what I changed.

                主控制器保持不变.

                DAO 控制器添加了一些东西.

                DAO Controller a couple of things were added.

                class DatabaseController extends Controller{
                    protected  $entityManager;
                
                    public function __construct($entityManager) {
                        $this->entityManager = $entityManager;
                    }
                public function getReferralIdByHash($hash)
                    {
                        $em = $this->entityManager;
                        $query = $em->createQuery(
                            'Select u From FuelFormBundle:UserReferrals u WHERE u.user_hash = :hash'
                        )->setParameter('hash', $hash);
                
                        $referral = $query->getResult();
                
                        if (!$referral) {
                            throw $this->createNotFoundException(
                                'No product referral found'
                            );
                            $logger = $this->get('logger');
                            $logger->info('I just got the logger');
                            $logger->crit('An error occurred, hash for referrals is not recognized. current hash is: ' . $hash . " .");
                            return $this->redirect($this->generateUrl('home'));
                        }
                
                        $clickThroughCount = $referral[0]->getClickThrough();
                        $referral[0]->setClickThrough($clickThroughCount + 1);
                        $em->flush();
                        return $referral;
                    }
                }
                

                服务最终看起来像这样

                services:
                     database_controller:
                          class:  FuelFormBundleControllerDatabaseController
                          arguments: ["@doctrine.orm.entity_manager"]
                

                推荐答案

                问题是这里没有将容器注入到控制器中.

                The problem is the container not being injected into the controller here.

                通常,如果您扩展 SymfonyBundleFrameworkBundleControllerController,Symfony 会自动执行此操作,它本身扩展 SymfonyComponentDependencyInjectionContainerAware:

                Normally, Symfony does this automatically if you're extending SymfonyBundleFrameworkBundleControllerController, which itself extends SymfonyComponentDependencyInjectionContainerAware:

                use SymfonyBundleFrameworkBundleControllerController;
                
                class YourController extends Controller
                

                使用 setter injection 调用方法 setContainer() 以容器为参数.

                The container is injected into the controller (if not explicitly defined as a service) using setter injection calling the method setContainer() with the container as an argument.

                现在,当您将控制器配置为服务时,您需要将 setContainer 调用添加到服务配置中:

                Now, as you configured your controller as a service you need to add the setContainer call to your service configuration:

                services:
                    database_controller:
                        class:  FuelFormBundleControllerDatabaseController
                        calls:
                            - [setContainer, ["@service_container"]]
                

                之后清除缓存.

                这篇关于FatalErrorException:错误:在非对象上调用成员函数 has()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <bdo id='u1OK0'></bdo><ul id='u1OK0'></ul>
                      <tbody id='u1OK0'></tbody>
                      <i id='u1OK0'><tr id='u1OK0'><dt id='u1OK0'><q id='u1OK0'><span id='u1OK0'><b id='u1OK0'><form id='u1OK0'><ins id='u1OK0'></ins><ul id='u1OK0'></ul><sub id='u1OK0'></sub></form><legend id='u1OK0'></legend><bdo id='u1OK0'><pre id='u1OK0'><center id='u1OK0'></center></pre></bdo></b><th id='u1OK0'></th></span></q></dt></tr></i><div id='u1OK0'><tfoot id='u1OK0'></tfoot><dl id='u1OK0'><fieldset id='u1OK0'></fieldset></dl></div>
                    • <legend id='u1OK0'><style id='u1OK0'><dir id='u1OK0'><q id='u1OK0'></q></dir></style></legend>

                        <small id='u1OK0'></small><noframes id='u1OK0'>

                          <tfoot id='u1OK0'></tfoot>