Zend Framework と phpMyAdmin (MySQL) を使用して、PHP で掲示板を作成しています。私は Zend Framework の初心者で、PHP をあまり使ったことがないので、回答はできるだけ単純にしてください。
掲示板の構造(セクション、アンダーセクション、アンダーアンダーセクション)をデータベースに保存しました。フォーラムのセクションとそれに対応する underSections を表示する必要があります。問題は、特定のセクションの下のセクションを表示するにはどうすればよいかということです。
IndexController.php
:
public function indexAction()
{
$sections = new Model_Sections();
$this->view->sections = $sections->fetchAll();
$undersections = new Model_Undersections();
$this->view->undersections = $undersections->fetchAll();
}
このコードでは、すべてのセクションとアンダーセクションのデータ (ID と名前) をフェッチします。
データベース モデルSection.php
:
class Model_Sections extends Zend_Db_Table_Abstract
{
protected $_name = 'sections';
}
データベース モデルUndersection.php
:
class Model_Undersections extends Zend_Db_Table_Abstract
{
protected $_name = 'undersections';
}
データの出力に関するメイン ビュー「index.phtml」のフラグメント:
<div class="section">
<?php foreach($this->sections as $sections) : ?>
<!-- Generates names of sections -->
<h1><?php echo $this->escape($sections->section_name);?></h1>
<!-- Generates names of undersections -->
<?php foreach($this->undersections as $undersections) : ?>
<div class="underSection">
<h2>
<a href=" ***link to some controller according to the undersection*** ">
<?php echo $this->escape($undersections->undersection_name);?>
</a>
</h2>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
現在、すべてのセクションの下にすべてのアンダーセクションが表示されます。