![]() |
How to load view if function not exists? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to load view if function not exists? (/showthread.php?tid=24187) Pages:
1
2
|
How to load view if function not exists? - El Forum - 11-02-2009 [eluser]codeworxx[/eluser] Hey Guys, me again ![]() I have an URL like this index.php/category/systems And a simple Controller: Code: class Listings extends Controller Now the View is not loaded (Error 404), because CodeIgniter is looking for the function 'systems', but "Systems" is the Category which i am looking for in the Database to create the View. So where's my Mistake? Thanks again, Sascha How to load view if function not exists? - El Forum - 11-02-2009 [eluser]pistolPete[/eluser] You could use the _remap() function: http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping But you still need one functione besides the constructor where you remap the requests to. How to load view if function not exists? - El Forum - 11-02-2009 [eluser]BrianDHall[/eluser] I think you could also use routes to reroute everything to listings/somefunction, but again you still need another function besides the controller. How to load view if function not exists? - El Forum - 11-02-2009 [eluser]jedd[/eluser] [quote author="codeworxx" date="1257215469"]Hey Guys, Now the View is not loaded (Error 404), because CodeIgniter is looking for the function 'systems', but "Systems" is the Category which i am looking for in the Database to create the View. So where's my Mistake? [/quote] My opinion (!) is that you should change your controller and method name to reflect the URL you are happy with. While I acknowledge that you can route around all kinds of mess, and no offence is intended here -- if you have to ask how to do this, then for the moment you should probably be adopting the simplest approach available. So, rather than trying to use this url: index.php/category/systems to get to this method: Controller / Listings ... I'd suggest you do the following: Try to think of your controller names as nouns, and your method names as verbs. That is, the controller handles a resource - a thing if you prefer - and your methods handle stuff you can do with those resources. Hence you might have a Listing controller with methods like 'show', 'edit', 'delete'. Don't put much in your constructor at all at this stage (as you've got here) as it will just confuse you. Similar you probably want to leave the index() method almost empty - perhaps a simple _remap() or redirect() to your default / preferred method. Don't use segment() calls unless you really need to - instead, for this kind of thing, you use the parameter feature for controller functions - a really feeble example follows: Code: // Somewhere in your Category controller How to load view if function not exists? - El Forum - 11-04-2009 [eluser]codeworxx[/eluser] Thanks all for your replys. I will read the #remap Infos. @jedd: The "Problem" is, that i create a Webshop System. The URLs are designed as follows: Categories e.g.: category/systems (pc systems) category/memory (ram, hd, ....) and so on then i have Listings e.g.: listings/systems/hewlettpackard listings/systems/acer and so on... The Categories and Listings are created dynamically. Also in Future search/my search phrase .... .... Greetings, Sascha How to load view if function not exists? - El Forum - 11-04-2009 [eluser]John_Betong[/eluser] [quote author="codeworxx" date="1257360577"]Thanks all for your replys. I will read the #remap Infos. @jedd: The "Problem" is, that i create a Webshop System. The URLs are designed as follows: Categories e.g.: category/systems (pc systems) category/memory (ram, hd, ....) and so on then i have Listings e.g.: listings/systems/hewlettpackard listings/systems/acer and so on... The Categories and Listings are created dynamically. Also in Future search/my search phrase .... .... Greetings, Sascha[/quote] I have a similar problem and have found one way that works for me ![]() Try this: Code: // ./config/routes.php } How to load view if function not exists? - El Forum - 11-04-2009 [eluser]jedd[/eluser] Quote:The "Problem" is, that i create a Webshop System. The URLs are designed as follows: Do you mean you have created, or you are about to create? Do you mean that the URLs are designed already, or that this is what you think you need to do in the application you haven't written yet? 'Designed' may be too strong a word, I think, here. I think if you just bring everything down a level, and have your dynamically created bits as the parameter to the method(s) in your controllers, your life will be somewhat easier. How to load view if function not exists? - El Forum - 11-04-2009 [eluser]codeworxx[/eluser] @John_Betong It's a nice start, but the categories may created, changed, added by the owner of the Shop, so i cannot define anything in the routes.php!! @Jedd I'm about to create - but the URL "Design" is ready and chosen by the Customer. With "Designed" I just mean how URLs have to look like. What do you mean with "bring everything down a level"??? Don't understand that?!?! How to load view if function not exists? - El Forum - 11-04-2009 [eluser]jedd[/eluser] [quote author="codeworxx" date="1257372504"] What do you mean with "bring everything down a level"??? Don't understand that?!?! [/quote] Have your dynamically created bits as the parameter to the method(s) in your controllers. Consequently have methods like Categories() and Listings() - though as I said before, I think having nouns as methods is ultimately confusing. How to load view if function not exists? - El Forum - 11-04-2009 [eluser]codeworxx[/eluser] You mean e.g. Code: shop/categories/... ??? Where "shop" is the Controller and "categories" and "listings" is the method? |