Hi
I'm working on a CMS based on ZF, and I want to be able to build the menu from a menutree in the database. I have a db-structure with parentID, subjectand menuID.
And I've done so that the links goes like this in my controller (I know this is huuuuge bad practice in MVC):
Code:
public function menuRecursivly($parent,$level=0, $list='')
{
if (!isset($this->return))
$this->return = '';
if ($level == 0)
$this->return .= "<ul id=\"nav\">";
else
$this->return .= "<ul id=\"nav".$parent."\">\n";
$query = "SELECT type, parentID, menuID, subject, url FROM tbl_menu WHERE parentID = ? ORDER BY sort ASC";
$result = Zend_Registry::get(dbAdapter)->fetchAll($query, $parent);
$list .= "/".$parent;
foreach ($result as $r)
{
if ($r['type'] == 'text')
$link = $this->_request->getBaseUrl()."".$list."/".$r['menuID'];
elseif ($r['type'] == 'menu')
$link = "#";
else
$link = $this->_request->getBaseUrl()."".$list."/".$r['menuID'];
$this->return.= "<li id=\"".$r['menuID']."\"><a href=\"".$link."\">".$r['subject']."</li>\n";
$this->menuRecursivly($r['menuID'], $level+1, $list);
}
$this->return.= "</ul>\n";
return $this->return;
}
How do I then do a rewrite rule to match ex.
http://localhost/1/1 with 1 as the main "parentID" and then pass all the ID:s as params to my controller? For example the URI can be
http://localhost/2/1/4/5
/Anders Hassis