NEW QUESTION -> LAST POST..Categories/URI/Maybe Model/Controller help? Code inside. |
[eluser]ColinHoernig[/eluser]
Basically, I'm just starting to use the whole "MVC" framework style and I'm having some issues grasping some things.. Here is my products controller: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); parts of Products model: Code: //get all products in table Parts of categories_model: Code: //get all categorys in table What I'm trying to do is make it so that if they have already selected a category from the products VIEW, then it will change the query and only show them the products in that category. My view looks like this: Code: <div id="categories"> I don't even know if what I'm doing is even close to how I should do it, and I've never had to do this in PHP before. So far the view loops through the categories and displays them all with a link like "products/category/1" where 1 is the category_id and it also loops through displaying all products correctly. If someone could point me in the right direction that would be great. Thank you so much to anybody who helps.
[eluser]neen[/eluser]
Pretty simple, really... Something like this in a controller Code: function categoryProducts($id) Then in your model (assuming you use AR as you did above): Code: function getProducts($id)
[eluser]ColinHoernig[/eluser]
EDIT: Actually, this works fine! The problem was in my autoload, it was trying to load a model that had a ton of errors and it just quit loading the page. Well I had it partially working yesterday..fooled with it today without testing on the server and now it's all broken.. Heres my new code: products view (products.php) Code: <?php products controller (products.php) Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Same models as first post. When I load (in MAMP) http://localhost:8888/sitename/index.php/products/ I don't get an error, so it's getting to the controller, but I get just a blank page with absolutely no client side source code. Can someone please help? I don't know what I'm doing wrong .
[eluser]ColinHoernig[/eluser]
One more question, how would I go about selecting all the products in all of the subcategories listed? For instance, if I click the product category "Apparel" which contains the subcategories "Shirts", "Pants", "Jackets", etc, I want the page to display all of the products that are located in all of the subcategories (because the subcategories are just being used to limit the selection). If anybody could help me out that would be great!
[eluser]MEM[/eluser]
Have you found your solution? I'm following Professional Codeginiter Book as well, and I have doubts about, how to deal with n categories instead of two. Regards, Márcio |
Welcome Guest, Not a member yet? Register Sign In |