Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > symfony
symfony Forum d'entraide sur le framework PHP symfony. Avant de poster : cours symfony et FAQ symfony
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 02/12/2011, 18h38   #1
Futur Membre du Club
 
FX
Inscription : juillet 2010
Messages : 75
Détails du profil
Informations personnelles :
Nom : FX

Informations forums :
Inscription : juillet 2010
Messages : 75
Points : 17
Points : 17
Par défaut setTemplate après insertion

bonjour,

j'ai une action d'ajout d'attribut qui fonctionne, je souhaite suite à l'enregistrement afficher tous les attribut liés à une photo.

voici mon code dans le fichier action :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   //Ajoute un attribut a un fichier
  public function executeAddattributsfichier(sfWebRequest $request)
  {
  	//Si pas une appelée par autre chose qu'une requête Ajax alors on renvoi erreur 404
	$this->forward404Unless($request->isXmlHttpRequest());
 
	$idfichier = $request->getParameter('fichier_id');
 
	//Enregistre attribut fichier
	$attribut = new Fichierattribut();
	$attribut->fichier_id = $request->getParameter('fichier_id');
	$attribut->intitule = $request->getParameter('attribut');
	$attribut->valeur = $request->getParameter('value');
	$attribut->save();
 
	//Renvoi les attributs pour MAJ de l'affichage
	$this->fichierattributs = Doctrine::getTable('fichierattribut')
	  ->createQuery('a')
	  ->where('fichier_id = ?',$idfichier)
	  ->execute();
 
	$this->setTemplate('infosfichier');
  }
Seulement, cela m'affiche autant de fois le template que d'attribut présent pour la photo. Si j'ai 10 atrtibut pour ma photo, il me réaffiche à suivre 10 fois le template.

J'ai pourtant le code ci-dessous qui fonctionne bien pour la suppression d'un attribut.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  public function executeDeleteattributsfichier(sfWebRequest $request)
  {
	//Si pas une appelée par autre chose qu'une requête Ajax alors on renvoi erreur 404
	$this->forward404Unless($request->isXmlHttpRequest());
 
	$idfichier = $request->getParameter('id');
	$nomattribut = $request->getParameter('name');
 
	$delete = Doctrine::getTable('fichierattribut')
				->createQuery('a')
				->where('fichier_id = ?',$idfichier)
				->andWhere('intitule = ?',$nomattribut)
				->execute();
 
	$delete = $delete->getFirst();
 
	$delete->delete();
 
	//Renvoi les attributs pour MAJ de l'affichage
	$this->fichierattributs = Doctrine::getTable('fichierattribut')
	  ->createQuery('a')
	  ->where('fichier_id = ?',$idfichier)
	  ->execute();
 
	$this->setTemplate('infosfichier');
  }
si quelqu'un peut m'indiquer pourquoi cela se dupplique.
pixworld est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/12/2011, 11h58   #2
Membre chevronné
 
Avatar de kenny.kev
 
Homme
Inscription : janvier 2007
Messages : 575
Détails du profil
Informations personnelles :
Sexe : Homme
Âge : 27
Localisation : France, Indre et Loire (Centre)

Informations professionnelles :
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : janvier 2007
Messages : 575
Points : 690
Points : 690
Envoyer un message via MSN à kenny.kev
Le problème ne vient pas forcément de la, mais de la Vue "infosfichier", tu ne ferais as une boucle de dans permettant d'afficher le contenu de ton objet ?
kenny.kev est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/12/2011, 14h04   #3
Futur Membre du Club
 
FX
Inscription : juillet 2010
Messages : 75
Détails du profil
Informations personnelles :
Nom : FX

Informations forums :
Inscription : juillet 2010
Messages : 75
Points : 17
Points : 17
bonjour,

voici la vue infosfichier, il y a en effet une boucle qui permet de lister les attributs.


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script type="text/javascript">
$(document).ready(function(){
 
	$("#add_attribut").click(function(){
		var fichier_id = $("#attribut_fichier_id").val();
		var attribut =  $("#attribut_attribut").val();	
		var value =  $("#attribut_value").val();
	   $(".infos-fichier-infounitaire").load("<?php echo url_for('add_attributsfichiers'); ?>", {fichier_id: fichier_id, attribut: attribut, value:value} );
	  return false;
	});
 
});
</script>
 
<?php $fichier_id = $fichierattributs->getFirst()->getFichier_id(); ?>
 
<!-- ajout attribut fichier -->
<?php if($sf_user->hasCredential('fichier'.$fichier_id.'edit')) { ?>
					<form method="get" action="<?php echo url_for('add_attributsfichiers') ?>" id="formu-attribut">
						<table style="margin-top:-5px;margin-bottom:2px;">
							<tr>
								<td style="float:left;"><input type="text" id="attribut_attribut" style="font-size:10px;width:100px;" name="attribut_attribut" value="<?php echo __("Add an attribute"); ?>..." 
								onfocus="if(this.value=='<?php echo __("Add an attribute"); ?>...') { this.value=''; }" 
								onblur="if(this.value=='') { this.value = '<?php echo __("Add an attribute"); ?>...' ;} " /></td>
								<td><input type="text" id="attribut_value" style="font-size:10px;width:100px;" name="attribut_value" value="<?php echo __("Add a value"); ?>..." 
								onfocus="if(this.value=='<?php echo __("Add a value"); ?>...') { this.value=''; }" 
								onblur="if(this.value=='') { this.value = '<?php echo __("Add a value"); ?>...' ;} " />
								<input type="hidden" id="attribut_fichier_id" name="attribut_fichier_id" value="<?php echo $fichier_id; ?>"/>
								</td>
								<td><a href="#add" title="<?php echo __("Add an attribute"); ?>"><img border="0" src="/images/icones/tag_blue_add.png" title="<?php echo __("Add an attribute"); ?>" id="add_attribut"/></a>
								</td>
							</tr>
						</table>
					</form>
<?php } ?>
<!-- parcours attribut fichier -->
 
<div class="infos-fichier-infounitaire"><span class="infos-titre"><?php echo __("File Id"); ?> :</span><span> <?php echo $fichier_id; ?></span></div>
<?php if($sf_user->hasCredential('fichier'.$fichier_id.'edit')) { ?>
	<?php $i = 0; ?>
	<input type="hidden" id="fichier_id" value="<?php echo $fichier_id; ?>" />
	<?php foreach($fichierattributs as $fichierattribut): ?>
		<input type="hidden" id="intitule_<?php echo $i; ?>" value="<?php echo $fichierattribut->getIntitule(); ?>" />
		<div class="infos-fichier-infounitaire" id="<?php echo $i; ?>"><span id="delete_<?php echo $i; ?>"><a href="#delete" title="<?php echo __("Delete"); ?>" onclick="$('#infos-fichier-infos').load('<?php echo url_for('delete_attributsfichiers');?>', {id: '<?php echo $fichier_id; ?>', name: '<?php echo $fichierattribut->getIntitule(); ?>'});"><img src="/images/icones/textfield_delete.png" alt="<?php echo __("Delete"); ?>" title="<?php echo __("Delete"); ?>" border="0"/></a></span> <span class="infos-titre"><?php echo __($fichierattribut->getIntitule()); ?> :</span> <span class="editable" id="<?php echo $i; ?>"><?php echo $fichierattribut->getValeur(); ?></span></div>
		<?php $i++; ?>
	<?php endforeach; ?>
<?php } else { ?>
	<?php foreach($fichierattributs as $fichierattribut): ?>
		<div class="infos-fichier-infounitaire"><span class="infos-titre"><?php echo __($fichierattribut->getIntitule()); ?> :</span> <span><?php echo $fichierattribut->getValeur(); ?></span></div>
	<?php endforeach; ?>
<?php } ?>
pixworld est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 15h20.


 
 
 
 
Partenaires

Hébergement Web