我正在使用 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>
目前它显示每个部分下的所有下部分。