Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2007, 06:29 AM
Junior Member
 
Join Date: Aug 2007
Posts: 7
Default Recursive rewrite-rule

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 09:06 PM.