0

indexSuccess.phpカテゴリのタイトルとそのカテゴリの要素に表示したい。これらは私の2つのテーブルです:

SgpsCategories:
  columns:
    description: { type: string(255), notnull: true }

SgpsCertificats:
  actAs: { Timestampable: ~ }
  columns:
    categories_id: { type: integer, notnull: true }
    titre: { type: string(255), notnull: true }
    type: { type: string(255), notnull: true }
    taille: { type: string(50), notnull: true }
    chemin: { type: string(255), notnull: true }
  relations:
    SgpsCategories: { onDelete: CASCADE, local: categories_id, foreign: id }

これまでのところ、アクションでこれを行いました:

 public function executeIndex(sfWebRequest $request)
  {


    $this->categories = Doctrine_core::getTable('SgpsCategories')
        ->createQuery('b')
        ->execute();

    $this->sgps_certificatss = Doctrine_Core::getTable('SgpsCertificats')
      ->createQuery('a')
      ->execute();
  }

そして、私はindexSuccess.phpでこれを行いました:

<?php foreach ($categories as $categorie): ?>

    <div id="titulo-certificado"><?php echo $categorie->getDescription(); ?></div>

    <?php foreach ($sgps_certificatss as $sgps_certificats): ?>

      <?php echo $sgps_certificats->getTitre()."<br>";?>

    <?php endforeach; ?>
<?php endforeach; ?>

ここで何が間違っていますか?ありがとうございました

4

1 に答える 1

0

データをフェッチするときに、2つのテーブル間の関係を使用していません。そして、あなたが行ったようにクエリを実行すると、データベースからすべてのカテゴリとすべての証明書(カテゴリのすべての証明書ではありません)が取得されます。

すべての要素を含むページに1つのカテゴリのみを表示する場合は、クエリを変更して、必要なカテゴリを指定する1つのカテゴリのみをフェッチし(-> fetchOne()を参照)、2番目のwhere句でそのIDを使用します。クエリ。または、それらを結合して1つのクエリのみを使用します。

すべてのカテゴリとその要素を1つのページに表示する場合は、リレーションSgpsCategoriesにforeignAliasを追加して、SgpsCategoriesからすべての要素を取得できるようにします。

SgpsCategories:
  columns:
    description: { type: string(255), notnull: true }

SgpsCertificats:
  actAs: { Timestampable: ~ }
  columns:
    categories_id: { type: integer, notnull: true }
    titre: { type: string(255), notnull: true }
    type: { type: string(255), notnull: true }
    taille: { type: string(50), notnull: true }
    chemin: { type: string(255), notnull: true }
  relations:
    SgpsCategories: { onDelete: CASCADE, local: categories_id, foreign: id, foreignAlias: Certificats }

だからあなたの行動:

public function executeIndex(sfWebRequest $request)
{
  $this->categories = Doctrine_core::getTable('SgpsCategories')
      ->createQuery('b')
      ->execute();
}

そしてあなたのテンプレート:

<?php foreach ($categories as $categorie): ?>

    <div id="titulo-certificado"><?php echo $categorie->getDescription(); ?></div>

    <?php foreach ($categorie->getCertificats() as $sgps_certificats): ?>

      <?php echo $sgps_certificats->getTitre()."<br>";?>

    <?php endforeach; ?>
<?php endforeach; ?>
于 2011-11-28T08:36:22.857 に答える