简体   繁体   English

试图调用 class “App\Controller\ApiController” 的名为“getPosition”的未定义方法

[英]Attempted to call an undefined method named “getPosition” of class “App\Controller\ApiController”

I am trying to instantiate a domain object in my controller but I am getting this error "Attempted to call function "getPosition" from namespace "App\Controller"".我正在尝试在我的 controller 中实例化域 object 但我收到此错误“尝试从命名空间“App\Controller 调用 function”“getPosition”。

I hope you can help me, whit that problem.我希望你能帮助我,解决这个问题。 This is me error这是我的错误

But i have get and set then why he don't find it?但是我已经得到并设置了为什么他没有找到它?

ApiController ApiController

<?php

namespace App\Controller;

use App\Entity\Domain;
use App\Repository\DomainRepository;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use GeoIp2\Database\Reader;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;

/**
 * @Route("/api")
 */
class ApiController extends AbstractFOSRestController
{
    /**
     * @Rest\Get("/domain", name="get_domain")
     * @Rest\Get("/domain/{blocked}")
     *
     * @throws
     */
    public function getDomain(Request $request, Reader $reader, DomainRepository $domainRepository, MailerInterface $mailer): JsonResponse
    {
        $record = $reader->country('87.99.79.119');
        $code   = $record->country->isoCode;
        $domain = $domainRepository->getDomain($code);
        $ip     = $request->getClientIp();
        if ($request->isXmlHttpRequest()) {
            $domain = $domainRepository->getDomain($code);
        }
        $position = getPosition();
        //
        //        $email = (new Email())
        //            ->from('noreply@makaobet.com')
        //            ->to('support@makaobet.com')
        ////            ->cc('cc@example.com')
        ////            ->bcc('bcc@example.com')
        ////            ->replyTo('fabien@example.com')
        ////            ->priority(Email::PRIORITY_HIGH)
        //            ->subject('Domain Error')
        //            ->html($domain->getDomain() . ' have problem!');
        //
        //        $mailer->send($email);

        return new JsonResponse(
            [
                'status' => 'ok',
                'domain' => $domain->getDomainName(),
            ], 200);
    }
}

Domain Entity域实体

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Entity(repositoryClass="App\Repository\DomainRepository")
 */
class Domain
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $domain_name;

    /**
     * @ORM\Column(type="array")
     */
    private $blocked_countries;

    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(type="integer")
     */
    private $position;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getDomainName(): ?string
    {
        return $this->domain_name;
    }

    public function setDomainName(string $domain_name): self
    {
        $this->domain_name = $domain_name;

        return $this;
    }

    public function getBlockedCountries(): ?array
    {
        return $this->blocked_countries;
    }

    public function setBlockedCountries(array $blocked_countries): self
    {
        $this->blocked_countries = $blocked_countries;

        return $this;
    }

    public function getPosition(): ?int
    {
        return $this->position;
    }

    public function setPosition($position): self
    {
        $this->position = $position;

        return $this;
    }
}

How can I make this work???我怎样才能使这项工作?

In order to get this tow work, anything you call from repository shoulkd be like:为了让这个拖曳工作,你从存储库调用的任何东西都应该是:

$domainRepository->getSomethig();

and same for setting:和设置相同:

$domainRepository->setSomething("some Value");

So in your case:所以在你的情况下:

$position = $domainRepository->getPosition();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试调用类“ AppBundle \\ Controller \\ DefaultController”的未定义方法“ getRequest” - Attempted to call an undefined method named “getRequest” of class “AppBundle\Controller\DefaultController” 尝试调用类“ App \\ Twig \\ AppExtension”中名为“ getDoctrine”的未定义方法 - Attempted to call an undefined method named “getDoctrine” of class “App\Twig\AppExtension” 试图调用一个未定义的名为“查询”的类的方法 - Attempted to call an undefined method named “query” of class 尝试调用类的名为“ getEntityManager”的未定义方法 - Attempted to call an undefined method named “getEntityManager” of class 尝试调用类的名为“ renderView”的未定义方法 - Attempted to call an undefined method named “renderView” of class 尝试调用类“ Swift_Mailer”的名为“ getContext”的未定义方法 - Attempted to call an undefined method named “getContext” of class “Swift_Mailer” 尝试调用类“ DOMElement”的未定义方法“ filter” - Attempted to call an undefined method named “filter” of class “DOMElement” 尝试调用类“ Knp \\ Menu \\ MenuItem”的名为“ setCurrentUri”的未定义方法 - Attempted to call an undefined method named “setCurrentUri” of class “Knp\Menu\MenuItem” 试图调用类“ MailController”的未定义方法“ get” - Attempted to call an undefined method named “get” of class “MailController” PHP 7.2.7:尝试调用类“ZipArchive”的名为“setEncryptionName”的未定义方法 - PHP 7.2.7: Attempted to call an undefined method named “setEncryptionName” of class “ZipArchive”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM