Welcome Guest, Not a member yet? Register   Sign In
Parsing nested lists
#1

[eluser]slowgary[/eluser]
Hi all,

I'm new to OOPHP, MVC, and CI but I must say I'm loving the experience. CodeIgniter has made everything so easy that it just makes sense, even to someone like me that resisted the move to OO for such a long time.

I'm creating a lightweight CMS for the experience and I could really use the help of some of you seasoned veterans around this forum. My problem exists in my menu manager. It allows users to drag and drop elements of the navigation around to suit their needs (uses JavaScript), which works fine. The issue is in saving it back to the database.

The site navigation would be a CSS dropdown menu, database driven, organized into nested lists like so:
Code:
<ul>
     <li>link 1</li>
     <li>link 2</li>
     <li>link 3
          <ul>
               <li>link 4</li>
               <li>link 5</li>
               <li>link 6
                    <ul>
                         <li>link 7</li>
                    </ul>
               </li>
          </ul>
     </li>
</ul>

And the database table structure:
Code:
--------------------------------------
|  id   |   position   |   caption   |
--------------------------------------
|  1    |      1       |    link 1   |
|  2    |      2       |    link 2   |
|  3    |      3       |    link 3   |
|  4    |      3.1     |    link 4   |
|  5    |      3.2     |    link 5   |
|  6    |      3.3     |    link 6   |
|  7    |      3.3.1   |    link 7   |
--------------------------------------

I've already created the necessary functionality to generate the navigation from the above table, what I'm having problems with is creating a management tool. The JavaScript works great, but so far the best method I can come up with to save the changes to the database is to send an AJAX request with the markup from the reordered list, then use PHP to parse it and update the necessary rows. I don't know where to start in implementing this. I'll be able to AJAX the markup to a PHP script, so I'd have something like this:

Code:
$markup =
"<ul>
     <li>link 1</li>
     <li>link 2</li>
     <li>link 3
          <ul>
               <li>link 4</li>
               <li>link 5</li>
               <li>link 6
                    <ul>
                         <li>link 7</li>
                    </ul>
               </li>
          </ul>
     </li>
</ul>";

Parsing this HTML with PHP is where I get lost. If I can turn the nested lists into an associative array I can figure the rest out. Can you (yeah YOU) throw me a hint on how to do this? Or maybe I'm going about this whole thing the wrong way? I would so much appreciate your expertise.

You can check an example navigation here-> aaroncicali.com/pages/home

And the sweet drag & drop manager here-> aaroncicali.com/menu

Thank you for taking the time to read this, I appreciate any efforts you send my way.


Messages In This Thread
Parsing nested lists - by El Forum - 03-21-2009, 09:25 PM
Parsing nested lists - by El Forum - 03-21-2009, 10:07 PM
Parsing nested lists - by El Forum - 03-21-2009, 11:28 PM
Parsing nested lists - by El Forum - 03-21-2009, 11:52 PM
Parsing nested lists - by El Forum - 03-22-2009, 12:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB