This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » [solved] 'echo url_for' question
[solved] 'echo url_for' question [message #102816] Tue, 20 July 2010 17:41 Go to next message
paolo892  is currently offline paolo892
Messages: 17
Registered: November 2009
Junior Member
Hello everyone,

I need a small correction in a piece of code (in /lib/model/) because it does not work properly;
In short: I have 2 tables (TPersonale - TGruppo) related to n: m; when I open the show of TGruppo table, I would like to have links that leads directly to the record for each connected IdPersonale. Now does not work properly because instead of giving me as many links as individuals associated with group, it is given a single link Sad. Here is the code: Here is the code:

showSuccess.php
      <th>People:</th>
      <td><ul class="sf_admin_td_actions"><a href="<?php echo url_for('personalewith/show?id_personale='.$t_gruppo->getPersoneId()) ?>"><?php echo $t_gruppo->getPersone() ?></ul></td></a>
    </tr>	



TGruppo.php

	public function getPersoneId(){
		$c = new Criteria();
		$c->add(TGruppoHasTPersonalePeer::T_GRUPPO_ID_GRUPPO, $this->getPrimaryKey());
		$persones = TGruppoHasTPersonalePeer::doSelect($c);
		$list = "";
		foreach ($persones as $p){
			$persone = TPersonalePeer::retrieveByPk($p->getTPersonaleIdPersonale());
			$list .= ($list != "") ? '; ' . $persone->getIdPersonale() : $persone->getIdPersonale();
		}
		return $list;
	}


Is there anyone who can tell me how to fix TGruppo.php?

thank you very much

Paolo Tomè

[Updated on: Wed, 21 July 2010 13:07]

icon14.gif  Re: 'echo url_for' question [message #102822 is a reply to message #102816 ] Tue, 20 July 2010 20:07 Go to previous messageGo to next message
myuser  is currently offline myuser
Messages: 11
Registered: July 2010
Junior Member
I think the url_for() helper function will only return one link at a time, for each object.

[optional] What I suggest is you create the list like you are doing and then assign it to $this->list so it will be automatically available in the template.

Then using the list of objects (if you created & assigned the list like I suggested in optional) you can iterate through the list accessing each object using this format (pseudo code)

foreach($this->list as $object)
  url_for(path,$object)
endforeach


I hope this helps you I am still working on the tutorial and have yet to write some symfony code of my own. Smile


Symfony 1.4
Fedora release 11 (Leonidas)
(PostgreSQL) 8.3.11
PHP 5.2.13 (cli)
IP address: haha ummm maybe next time
Re: 'echo url_for' question [message #102847 is a reply to message #102816 ] Wed, 21 July 2010 10:42 Go to previous messageGo to next message
paolo892  is currently offline paolo892
Messages: 17
Registered: November 2009
Junior Member
Thank you very much for the suggestion,
I'm not very skilled at writing code because I'm still a beginner, therefore I can't realize what you have suggested me. You would do me a big favor by indicating how I should write better code!
I thank you again
Paolo
Re: 'echo url_for' question [message #102871 is a reply to message #102847 ] Wed, 21 July 2010 13:07 Go to previous message
paolo892  is currently offline paolo892
Messages: 17
Registered: November 2009
Junior Member
I solved the correct code is:

showSuccess.php

      <th>People:</th>
      <td><?php $lista = $t_gruppo->getPersoneId();?>
      <ul>
      <?php foreach($lista as $p): ?>
      <ul><a href="<?php echo url_for('personalewith/show?id_personale=' . $p['id_personale'])?>">
      <?php  echo $p['persona'];?></ul>
	<?php endforeach;?>
		  </a></ul></td>


TGruppo.php
	public function getPersoneId(){
		$c = new Criteria();
		$c->add(TGruppoHasTPersonalePeer::T_GRUPPO_ID_GRUPPO, $this->getPrimaryKey());
		$persones = TGruppoHasTPersonalePeer::doSelect($c);
		$list = array();
		foreach ($persones as $p){
			$persone = TPersonalePeer::retrieveByPk($p->getTPersonaleIdPersonale());
			$list[] = array ('id_personale' => $persone->getIdPersonale(),
							 'persona' => $persone->getCognome().' '. $persone->getNome()
			);
	}
		return $list;
	}


Thank you so much!!

Paolo
Previous Topic:sfPropelBehavior::registerHooks and doSelect
Next Topic:Problème d'insertion SQL avec relation sur doctrine
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software