在这里,我的数据库中有一个保险表,用于存储医生可以关联的保险(带有其名称和徽标)。现在,医生可以在其医生空间中选择一个,两个或不选择任何保险。但是,我有一个问题,当医生不隶属于任何保险时,我想选择一个默认值,表明该医生还没有保险,但是我选择的不是保险的任何事情都不会生效。
控制器
String[] projection = {DataContract.DataEntry._ID,
DataContract.DataEntry.COLUMN_PROJECT_NAME,
DataContract.DataEntry.COLUMN_HEAD,
DataContract.DataEntry.COLUMN_CITY,
DataContract.DataEntry.COLUMN_COST};
树枝
public function editAction(Request $request)
{
$user = $this->getUser();
if ($user === null) {
throw new NotFoundHttpException('Utilisateur Inexistant');
}
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('DoctixMedecinBundle:Medecin');
$specialiteRepo = $em->getRepository('DoctixAdminBundle:Specialite');
$cliniqueRepo = $em->getRepository('DoctixAdminBundle:Clinique');
$assuranceRepo = $em->getRepository('DoctixMedecinBundle:Assurance');
$object = $assuranceRepo->findOneBy(array('id' => $request->get('assurance')));
$medecin = $repo->findOneBy(array(
'user' => $user,
));
if ($request->isMethod('POST')) {
if ( ($pass = $request->get('pass')) != ''){
$medecin->getUser()->setSalt('');
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($medecin->getUser());
$password_encoder = $encoder->encodePassword($pass, $medecin->getUser()->getSalt());
$medecin->getUser()->setPassword($password_encoder);
}
$medecin->setSpecialite($specialiteRepo->find($request->get('specialite')));
$medecin->setClinique($cliniqueRepo->find($request->get('clinique')));
$medecin->getUser()->setAdresse($request->get('adresse'));
$medecin->getUser()->setNumTel($request->get('telephone'));
$medecin->setQuartier($request->get('quartier'));
$medecin->setNumOrdre($request->get('numordre'));
if ($object) {
$medecin->addAssurance($object);
}
$em->persist($medecin);
$em->flush();
// redirection avec le status http 301 ::)))))
$url = $this->generateUrl('medecin_parametre');
return $this->redirect($url, 301);
} else {
return $this->render('DoctixMedecinBundle:Medecin:editProfile.html.twig', array(
'medecin' => $medecin,
'specialites' => $specialiteRepo->findAll(),
'cliniques' => $cliniqueRepo->findAll(),
'assurances' => $assuranceRepo->findAll()
));
}
}
树枝视图,将显示或不显示医生所属的保险
<div class = "col-md-6">
<div class="form-group">
<label for="assurance" class="control-label">Assurance </label>
<select id="assurance" class="form-control" placeholder="Assurance" name="assurance" multiple >
<option value="Pas d Assurance" selected="Pas encore">Pas d'Assurance</option>
{% for assurance in assurances %}
<option value="{{ assurance.id }}"
{% for it in medecin.assurance %}
{{ it.id == assurance.id ? 'selected' : '' }}
{% endfor %} >{{ assurance.nom|upper }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row">
<div class="col-md-offset-3 col-md-3">
<input type="submit" class="btn_1 btn-success medium" form="editProfil" value="Valider">
<a href="{{ path('medecin_parametre') }}" class=" btn_1 btn-danger medium">Annuler </a>
</div>
</div>
现在当医生没有保险时,如何显示一段说“没有保险”的文字? 谢谢。
答案 0 :(得分:0)
要检查医学药物是否有任何保证,您必须检查数组{% if medecin.assurance is empty %}
{# This medecin has no assurances, act accordingly #}
{% else %}
{# Display medecin's assurances #}
{% for item in medecin.assurance %}
{# Display each assurance #}
{% endfor %}
{% endif %}
是否为空
类似这样的东西:
<link href="../../../bower_components/iron-overlay-behavior/iron-overlay-behavior.html" rel="import">