属性“ pincode”或方法“ pincode()”,“ getpincode()” /“ ispincode()” /“ haspincode()”或“ __call()”都不存在[关闭]

问题描述 投票:-2回答:1

1。当我输入数据并单击提交按钮时,我会收到此错误。错误将显示在下面。

2.im在一页中为两个表单创建了单独的数据库表。

2.submit数据进入contactusnew变量,并且这是第一个表单数据插入到第一个数据库表中,但是第二个表单数据没有插入到第二个数据库表中。

4)但出现以下错误:

属性“ pincode”或方法“ pincode()”,“ getpincode()” /“ ispincode()” /“ haspincode()”或“ __call()”都不存在,并且不具有公共访问权限类“ SAMPLE \ SAMPLEBundle \ Entity \ ContactUsNew”。

ContactUsNew实体

/**
 * @var string
 * @ORM\Column(type="string", unique=false)
 * @Assert\NotBlank(message="Please enter your name.")
 * @Assert\Regex(
 *     pattern="/\d/",
 *     match=false,
 *     message="Your name cannot contain a number"
 * )
 */

protected $name = '';
public function getName() : string {
    return $this->name;
}
/**
 * @var string
 * @ORM\Column(type="string", unique=true)
 * @Assert\NotBlank
 * @Assert\Length(min=4, max=254, minMessage="wg.email.short", maxMessage="wg.email.long")
 * @Assert\Email(mode="strict")
 */
protected $emailid = '';
public function getEmailid() : string {
    return $this->emailid;
}

/**
 * @var string
 * @ORM\Column(type="string", unique=false)
 * @Assert\NotBlank(message="Please enter your mobile phone number")
 * @Assert\Regex(message="This does not appear to be a valid phone number.",pattern="/^(([(]?\d{3}[)]?[-. ]?\d{3}[-. ]?\d{4})$)/")
 */

protected $phonenumber = '';

public function getPhoneNumber() : string {
    return $this->phonenumber;
}

/**
 * @var string
 * @ORM\Column(length=4,type="string", unique=false)
 * @Assert\Length(
 *      min = 5,
 *      max = 50,
 *      minMessage = "Your first name must be at least {{ limit }} characters long",
 *      maxMessage = "Your first name cannot be longer than {{ limit }} characters",
 *      allowEmptyString = false
 * )
 */
protected $message = '';

public function getMessage() : string {
    return $this->message;
}

public function setAdress($adress)
{
    $this->adress = $adress;
}

/**
 * @var \Doctrine\Common\Collections\Collection<int, Adress>
 * @ORM\OneToMany(targetEntity="SAMPLE\SAMPLEBundle\Entity\Adress", mappedBy="contact_us_new", indexBy="id")
 */
protected $adress;
/** @return \Doctrine\Common\Collections\Collection<int, Adress> */
public function getAdress()
{
    return $this->adress;
}


 public function __construct(?Adress $adress)
{
    $this->user = $adress;

}

/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}

/**
 * @param string $name
 */
public function setName($name)
{
    $this->name = $name;
}

/**
 * @param string $emailid
 */
public function setEmailid($emailid)
{
    $this->emailid = $emailid;
}

/**
 * @param string $phonenumber
 */
public function setPhoneNumber($phonenumber)
{
    $this->phonenumber = $phonenumber;
}

/**
 * @param string $message
 */
public function setMessage($message)
{
    $this->message = $message;
}

public function  CreateFromFormData (?ContactUsNewFormData $formDatanew) : self {
    $fromObject = new ContactUsNew();

    if($formDatanew){
        $fromObject->setName($formDatanew->name);
        $fromObject->setEmailid($formDatanew->emailid);
        $fromObject->setPhoneNumber($formDatanew->phonenumber);
        $fromObject->setMessage($formDatanew->message);
    }
    return $fromObject;
}

public function updateCreateFromFormData(?ContactUsNewFormData $formDatanew) : void{

    $this->setName($formDatanew->name);
    $this->setEmailid($formDatanew->emailid);
    $this->setPhoneNumber($formDatanew->phonenumber);
    $this->setMessage($formDatanew->message);
}

地址实体

/**
 * @var int
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @var int
 * @Assert\NotBlank
 * @Assert\Type(type="digit")
 * @Assert\PositiveOrZero
 * @ORM\Column(type="integer")
 */
protected $pincode;

/**
 * @var string
 * @Assert\NotBlank
 * @ORM\Column(type="integer")
 */
protected $adress;



/** @var ContactUsNew */
private $contactusnew;

/**
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * @return mixed
 */
public function getPincode()
{
    return $this->pincode;
}

/**
 * @return mixed
 */
public function getAdress()
{
    return $this->adress;
}

/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}

/**
 * @param mixed $pincode
 */
public function setPincode($pincode)
{
    $this->pincode = $pincode;
}

/**
 * @param mixed $adress
 */
public function setAdress($adress)
{
    $this->adress = $adress;
}

public function setcontactnew(ContactUsNew $contactusnew )
{

    $this->contactusnew = $contactusnew;


}


public function  CreateFromFormData (?AdressFormTypeData $formDatanew) : self {
        $fromObject = new Adress();

        if($formDatanew){
            $fromObject->setPincode($formDatanew->pincode);
            $fromObject->setAdress($formDatanew->adress);
        }
        return $fromObject;
    }

    public function updateCreateFromFormData(?AdressFormTypeData $formDatanew) : void{

        $this->setPincode($formDatanew->pincode);
        $this->setAdress($formDatanew->adress);

    }

** ContactUsNewController **

/**
 *
 * @Route("/contactusnew/", name="contact_us_new", methods={"GET", "POST"})
 */
public function newAction(Request $request): Response
{
    return $this->editContactUsNew($request, null);
}

/**
 *
 * @Route("/list/", name="contact_us_list")
 * Method=({"GET","POST"})
 * 
 */
public function indexAction(): Response
{
    $em = $this->getDoctrine()->getManager();

    $entities = $em->getRepository(ContactUsNew::class)->findAll();

    return $this->render('index.html.twig', [

        'entities' => $entities
    ]);
}

/**
 *
 * @Route("/{id}", name="contact_show", methods="GET")
 */
public function showAction(ContactUsNew $contactusnew): Response
{
    $deleteForm = $this->createDeleteForm($contactusnew);
    return $this->render('showrecords.html.twig', [
        'entity' => $contactusnew,
        'delete_form' => $deleteForm->createView()
    ]);
}

private function editContactUsNew(Request $request,?ContactUsNew $contactusnew): Response
{

    if(!$contactusnew)
    {
        $contactusnew = new ContactUsNew(null);
    }

    $new = !$contactusnew;


    $dataclass = new ContactUsNewFormData($contactusnew);
    $adress_dto = new AdressFormTypeData ($contactusnew->getAdress());

    $dataclass->setadressdto($adress_dto);

    $form = $this->createForm(ContactUsNewForm::class, $dataclass);

    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {

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

        $adress = new Adress();
        $contactusnew->updateCreateFromFormData($dataclass);
        $adress->updateCreateFromFormData($adress_dto);
        $contactusnew->setAdress($adress);

            $em->persist($contactusnew);

             $em->flush();

        return $this->redirectToRoute('contact_us_list');
    }

    return $this->render('contact_us.html.twig', [
        'new' => $new,

        'form' => $form->createView(),
      $this->createCreateForm($contactusnew)->createView()),
    ]);
}

}

index.html.twig

<h1>Contactus list</h1>

<table class="records_list">
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Email</th>
            <th>Mobilenumber</th>
            <th>Message</th>
            <th>Actions</th>
             <th>Pincode</th>
            <th>Adress</th>
        </tr>
    </thead>
    <tbody>
    {% for entity in entities %}
        <tr>
            <td><a href="{{ path('contact_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
            <td>{{ entity.name }}</td>
            <td>{{ entity.emailid }}</td>
            <td>{{ entity.phonenumber }}</td>
            <td>{{ entity.message }}</td>


            <td>
            <ul>
                <li>
                    <a href="{{ path('contact_show', { 'id': entity.id }) }}">show</a>
                </li>
                <li>
                    <a href="{{ path('contactusnew_edit', { 'id': entity.id }) }}">edit</a>
                </li>
            </ul>
            </td>
            <td>{{ entity.pincode }}</td>
            <td>{{ entity.adress }}</td>
        </tr>
    {% endfor %}
    </tbody>

此代码中的问题是什么?

php symfony doctrine-orm symfony4 symfony-forms
1个回答
0
投票

您正在呼叫WG\WGBundle\Entity\Address,但您的实体名称为Adress,将其更改为WG\WGBundle\Entity\Adress

[建议:对于所有对象,您应该尝试在代码中仅使用一个拼写,例如:不要混用“地址”和“地址”,这将有助于您避免此类错误。

© www.soinside.com 2019 - 2024. All rights reserved.