最初にいくつかのコード、私の投稿の最後に質問。私のコードはDBからリストliulを生成します:
サンプルSQL:
CREATE TABLE IF NOT EXISTS `gallery` (
`idgallery` int(11) NOT NULL,
`name` varchar(45) NOT NULL,
`parent` varchar(45) DEFAULT '0',
`type` varchar(45) DEFAULT 'category',
`menu` varchar(45) NOT NULL,
PRIMARY KEY (`idgallery`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `gallery` (`idgallery`, `name`, `parent`, `type`, `menu`) VALUES
(1, 'Gallery', '0', 'Gallery', ''),
(2, 'Name', '1', 'category', ''),
(3, 'Name2', '0', 'category', ''),
(4, 'Name3', '3', 'category', ''),
(5, 'qwerty', '4', 'category', ''),
(6, 'child', '3', 'category', ''),
(7, 'child', '1', 'category', '');
このコードは、ZendFWに移行する前にうまく機能します。
$ro=mysql_query("SELECT * FROM gallery");
$rows=array();
while($rowek=mysql_fetch_object($ro))
{
$rows[]=$rowek;
}
echo mapTree($rows,0,"category");
function children($rows, $id) {
foreach ($rows as $row) {
if ($row->parent == $id)
return true;
}
return false;
}
function mapTree($rows, $parent = 0, $class = "none") {
$result = "<ul>";
foreach ($rows as $row) {
if ($row->parent == $parent) {
$result.= "<li class='$class'>$row->name";
if (children($rows, $row->idgallery))
$result.= mapTree($rows, $row->idgallery, "category");
$result.= "</li> ";
}
}
$result.= "</ul>";
return $result;
}
そして、ZendFWではActionHelperを使用しています。*すべてのオブジェクトDBがヘルパー(error_log)に渡されますが、表示されているのは次のとおりです。*
Gallery
Name
順調/スタイリングの2つのレコード...しかし、別の5つはどこにありますか?
インデックスアクション:
//preDispatch()
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
//IndexAction()
$gallery = new Application_Model_DbTable_Gallery;
$request = $gallery->fetchAll($gallery->select()->order("parent"));
$helper = $this->_helper->gallery->index($request);
$this->view->gallery = $helper;
アクションヘルパー
class Zend_Controller_Action_Helper_Gallery extends Zend_Controller_Action_Helper_Abstract{
function index($rows){
echo $this->mapTree($rows,0,"");
}
function children($rows, $id) {
foreach ($rows as $row) {
if ($row->parent == $id)
return true;
}
return false;
}
function mapTree($rows, $parent = 0, $class = "brak") {
$result = "<ul>";
foreach ($rows as $row) {
if ($row->parent == $parent) {
$result.= "<li class='$class'>$row->name";
if ($this->children($rows, $row->idgallery))
$result.= $this->mapTree($rows, $row->idgallery, "category");
$result.= "</li> ";
}
}
$result.= "</ul>";
return $result;
}
}
そしてまた見る...
<?php $this->gallery;?>
私の質問は、なぜZFのコードを完成できないのかということです。