Can you suggest a better URI vs CRUD system for a forum? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Can you suggest a better URI vs CRUD system for a forum? (/showthread.php?tid=52669) |
Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-20-2012 [eluser]nullsys[/eluser] Hi! I'm hoping you can help. I'm considering the best way to present a forums' URL, vs Controller setup. Here is what I'm thinking: Code: // Gets all categories Only the post_id will be numeric. My problem is this: Should I follow the standard CRUD format in the controller, and do the following for each create, retrieve, update and delete: Code: public function create() { I feel this would work, but I can't help feeling there is a more "codeigniter" way, using Routes or some such. Any feedback, suggestions or the likes would be greatly appreciated! Thank you. Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-20-2012 [eluser]CodeIgniteMe[/eluser] a separate function for each functionality is more object-oriented way of getting things done as to simplify the code contents. you can use the routes to re-route the execution to your CRUD controller: This example route will trigger once he encounters each of your given example routes Code: $route['(create|edit|delete)/(category|topic|post)/(:any)'] = 'CRUD/$1/$2/$3'; then at the controller, you can try it by having something like this Code: <?php Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-21-2012 [eluser]nullsys[/eluser] Hi! Thanks for the tips on route and CRUD. But I'm still a little confused. I like the $param system, but I'm still going to have to use the following: Code: if ($param1 === "category") { Inside each of the create/edit/delete methods right? otherwise, how else would the controller know which one I want to edit, etc. Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-21-2012 [eluser]PhilTem[/eluser] [quote author="nullsys" date="1340286836"] I like the $param system, but I'm still going to have to use the following: Code: if ($param1 === "category") { Inside each of the create/edit/delete methods right? otherwise, how else would the controller know which one I want to edit, etc.[/quote] You're right. However, I think you might also use Code: $route['(create|edit|delete)/(category|topic|post)/(:any)'] = 'CRUD/$2_$1/$3'; Watch the added underscore between $2 and $1 as well ass the switched parameters $1 and $2. That way (I'm not 100% sure this will work since my RegExp knowledge is very low) you can have methods like Code: function category_edit($param_3) {} And so on a so forth for topic and post the same. This would save you time writing the Code: if ($param1 === "category") { parts Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-21-2012 [eluser]nullsys[/eluser] HI Philterm, Thanks for that, I've been playing around, modified it further and come up with this: Code: public function create($param1='',$param2='') The reasoning behind it is trying to keep DRY code. Rather can repeat functions for each "category", "topic" etc. I can just use create(), edit(), etc. Can you seen any problems with this? Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-21-2012 [eluser]CodeIgniteMe[/eluser] Hi @PhilTem If you want to use this route Code: $route['(create|edit|delete)/(category|topic|post)'] = 'CRUD/$2_$1'; Code: function category_edit($param_3) {} @nulsys I like how you code, setting a reusable set of validation rules is the CodeIgniter way. However, you may not need to load the form helper because the form_validation library needs it and will load it automatically. Can you suggest a better URI vs CRUD system for a forum? - El Forum - 06-23-2012 [eluser]nullsys[/eluser] Thanks everyone. I appreciate that comment CodeIgniteMe too lol. I'm still working on it, but I learnt something here, so thanks all! |