Help converting small function to CI Framework... Newbie :/ |
[eluser]carlhussey[/eluser]
Hey guys. I'm trying to figure out how to write this function for my menu to work with CI and I was wondering if anyone could help me convert it so I can see how it was done. All its doing is pulling a menu from the database and formatting it with html. Id like to be able to just return is as a single value that I can send to my view. Code: <?php
[eluser]CI_avatar[/eluser]
Set you database configuration http://ellislab.com/codeigniter/user-gui...odels.html (See connection to database) Code: $hostname = 'localhost'; Make a model that will handle database query http://ellislab.com/codeigniter/user-gui...odels.html Code: $query = "SELECT * FROM menu WHERE parent = 0"; Make a view that will populate your output http://ellislab.com/codeigniter/user-gui...views.html Code: echo "<ul id=\"main-nav\">"; After making this part into MVC structure. Make a controller that will call your model (get the menus and pass it to the controller), if the controller have the menus, pass it to the view you have created.
[eluser]carlhussey[/eluser]
I understand the structure and how it to do each of the files but for example I dont believe "while ($d = $query->fetch(PDO::FETCH_ASSOC)) {" is something that would work in the CI framework so I was trying to find out its equivalent
[eluser]carlhussey[/eluser]
is WHILE and foreach the same then? I dont see any use of a while loop in those queries Like i said, I'm new to this so the below code is probably way off Code: <?php
[eluser]CI_avatar[/eluser]
yes your right. you can use foreach instead of while-loop.
[eluser]carlhussey[/eluser]
Pretty much got it figured out. Now I just need to figure out the URI part :/ Any tips for that part? I added some notes in the code to what I need to do Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |