Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Symfony 1.4 - pobieranie danych
Forum PHP.pl > Forum > PHP
damianooo
Witam,


Mam następujący schemat bazy z dwiema tabelami:

  1. Team:
  2. actAs:
  3. Timestampable: ~
  4. columns:
  5. name:
  6. type: varchar(100)
  7. notnull: true
  8.  
  9. Meet:
  10. actAs:
  11. Timestampable: ~
  12. columns:
  13. team1_id:
  14. type: integer
  15. notnull: true
  16. team2_id:
  17. type: integer
  18. notnull: true
  19. relations:
  20. Team1:
  21. class: Team
  22. local: team1_id
  23. foreign: id
  24. Team2:
  25. class: Team
  26. local: team2_id
  27. foreign: id






Jak widać Tabela MEET zawiera dwa pola z ID pochodzące z tabeli TEAM. Dzięki temu MEET (SPOTKANIE) to połącznie dwóch TEAM (DRUŻYN).

I teraz tak:

w Kontrolerze action.class.php w metodzie executeIndex() mam tak:

  1. $this->meets = MeetTable::getInstance()->findAll();


Natomiast w Widoku indexSuccess.php mam tak:

  1. <?php foreach ($meets as $meet):?>
  2. <?php echo $meet->getTeam1Id() . ' - ' . $meet->getTeam2Id()?>
  3. <br />
  4. <?php endforeach;?>




Nie wiem jednak jak wyświetlić nazwy drużyn zamiast ID

proszę o podpowiedź,

dzięki




szalek01
w modelu od Team
Kod
public function __toString()
  {
    return $this->getName();
  }
damianooo
ok tylko, że nie wiem jak się do tego dobrać z tego kodu który obecnie mam a więc:
  1. <?php foreach ($meets as $meet):?>
  2. <?php echo $meet->getTeam1Id() . ' - ' . $meet->getTeam2Id()?>
  3. <br />
  4. <?php endforeach;?>
szalek01
lib/model/Team.class.php tam to dodaj

dodatkowo w folderze base możesz podejrzeć jakie metody ma obiekt Team
damianooo
ok dodałem i jak powinieniem teraz to wywołać ?

Bo chciałbym coś na zasadzie:
  1. <?php foreach ($meets as $meet):?>
  2.  
  3. <?php echo $meet->getTeam1Id()->getTeam()->getName().' - '.$meet->getTeam2Id()?>
  4. <br />
  5.  
  6. <?php endforeach;?>


ale to nie działa więc penwie źle się do tego dobieram
szalek01
  1. <?php echo $meet->getTeam1(); ?>

w basach masz i tu znajdziesz metody które możesz wywołać na obiekcie Meet

/**
* BaseMeet
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $team1_id
* @property integer $team2_id
* @property Team $Team1
* @property Team $Team2
*
* @method integer getTeam1Id() Returns the current record's "team1_id" value
* @method integer getTeam2Id() Returns the current record's "team2_id" value
* @method Team getTeam1() Returns the current record's "Team1" value
* @method Team getTeam2() Returns the current record's "Team2" value
* @method Meet setTeam1Id() Sets the current record's "team1_id" value
* @method Meet setTeam2Id() Sets the current record's "team2_id" value
* @method Meet setTeam1() Sets the current record's "Team1" value
* @method Meet setTeam2() Sets the current record's "Team2" value
*
* @package test
* @subpackage model
* @author Your name here
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class BaseMeet extends sfDoctrineRecord
damianooo
ok dzięki działa ...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.