首页 > 解决方案 > 使用 symfony 3 按钮喜欢/不喜欢

问题描述

我在我的病人空间里有一个他预约过的医生的名单。在每个医生旁边,我想添加一个我喜欢的按钮,这样病人就可以知道他是否喜欢与医生的咨询。我想知道有多少患者喜欢某位医生。让这个数字显示在医生的详细信息中。

这是我的控制器,我有我的医生名单

控制器

 public function patientBookingListAction(Request $request)
{

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

    $medecin = $em->getRepository("DoctixMedecinBundle:Medecin")->findOneBy(array(
        'user' => $this->getUser(),
    ));

    $patient = $em->getRepository("DoctixPatientBundle:Patient")->findOneBy(array(
        'user' => $this->getUser(),
    ));

    $bookings = $em->getRepository("DoctixFrontBundle:Booking")->findBy(array(
        "patient" => $patient
    ));

    $bookings = $this->get('knp_paginator')->paginate($bookings, $request->query->get('page', 1), 3);


    return $this->render('DoctixPatientBundle:Patient:bookings.html.twig', array(
        'bookings' => $bookings
    ));
}

我已经创建了我的表 favorite_doctor :

实体 favourite_doctor

  class MedecinFavoris
 {
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;


/**
 * @ORM\ManyToOne(targetEntity="Doctix\PatientBundle\Entity\Patient", inversedBy="medecin_favoris")
 * @ORM\JoinColumn(name="patient_id", referencedColumnName="id")
 */
private $patient;

   /**
 * @ORM\ManyToOne(targetEntity="Doctix\MedecinBundle\Entity\Medecin", inversedBy="medecin_favoris")
 * @ORM\JoinColumn(name="medecin_id", referencedColumnName="id")
 */
private $medecin;



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

/**
 * Set patient
 *
 * @param \Doctix\PatientBundle\Entity\Patient $patient
 *
 * @return MedecinFavoris
 */
public function setPatient(\Doctix\PatientBundle\Entity\Patient $patient = null)
{
    $this->patient = $patient;

    return $this;
}

/**
 * Get patient
 *
 * @return \Doctix\PatientBundle\Entity\Patient
 */
public function getPatient()
{
    return $this->patient;
}

/**
 * Set medecin
 *
 * @param \Doctix\MedecinBundle\Entity\Medecin $medecin
 *
 * @return MedecinFavoris
 */
public function setMedecin(\Doctix\MedecinBundle\Entity\Medecin $medecin = null)
{
    $this->medecin = $medecin;

    return $this;
}

/**
 * Get medecin
 *
 * @return \Doctix\MedecinBundle\Entity\Medecin
 */
public function getMedecin()
{
    return $this->medecin;
}
 }

当我单击按钮时,我希望我的数据保存在此表中。

枝条

  {% for booking in bookings %}
        <div class="list_general" id="liste">
            <a href="#0" class="wish_bt"></a>
            <ul>
                <li>
                    <figure><img src="{{ vich_uploader_asset(booking.medecin.media, 'imageFile') }}"
                                                         alt="{{ booking.medecin.media.imagename }}"></figure>
                    <h4>Dr. {{ booking.medecin.user.prenom|capitalize }} {{ booking.medecin.user.nom|upper }} <i class="pending">Pending</i></h4>
                     <ul class="booking_details">
                        <li><strong>Date et heure</strong>{{ booking.dateHeureRdv|date('d/m/Y') }}</li>
                        <li><strong>Heure</strong>{{ booking.dateHeureRdv|date('H:i') }}</li>
                        <li><strong>Motif</strong>Consultation</li>
                        <li><strong>Téléphone</strong>{{ booking.medecin.user.numTel }}</li>
                        <li><strong>Email</strong>{{ booking.medecin.user.username }}</li>
                    </ul>
                    <ul class="buttons">
                        <li><a href="{{ path('patient_booking_deplacer', {'id': booking.id}) }}?medecin={{ booking.medecin.id }}" class="btn_1 gray approve"><i class="fa fa-fw fa-check-circle-o"></i> Déplacer Rdv</a></li>
                        <li><a href="{{ path('patient_booking_annuler', {'id': booking.id}) }}" class="btn_1 gray delete"><i class="fa fa-fw fa-times-circle-o"></i> Annuler</a></li>
                    </ul>
                </li>
                <div class="like">
                <a href="#" class="fa fa fa-thumbs-up">Like</a>
                </div>  
                </ul>

        </div>
    {% endfor %}    

现在我不知道当我点击喜欢按钮时该怎么做。知道当患者点赞时,数据必须在数据库中注册,并且点赞按钮也必须消失,以不再允许他投票两次或更多次。

非常感谢

标签: ajaxsymfonybutton

解决方案


推荐阅读