Controller question |
[eluser]Assim[/eluser]
Let's say I wanted to create controller like this: http://example.com/pages to load page list http://example.com/pages/something to load "something" Well here's the code that I wrote, I'm using the remap function and taking $PageSlug as the second URI segement. In the above example, "something" was the $PageSlug Code: <?php In the if statement, I can only load the page and not the page list. I tried writing it in the following ways: if(!$PageSlug) if(empty($PageSlug)) if($PageSlug = '') But still I can't load the page list which is when the $PageSlug is not provided. Does anybody have the solution to this problem?
[eluser]Ki[/eluser]
Keep in mind that (depending on your rerouting) the CI follows controller/function method in its uri calls. So, if you want to call pagelist, you need to have a function within your controller called page_list(or something similar)... so when your uri looks like this http://www.examples.com/pages/page_list, this will call the function page_list within your controller called Pages. Or you can build a routing to have everything after pages passed as variable, but then you may want to have something like http://www.examples.com/pages/page_list/1, this way your pages controller will have a uri array as [page_list]=1 and then you can use if( !empty(page_list) ){ do someting }
[eluser]Assim[/eluser]
[quote author="samota" date="1266803131"]Keep in mind that (depending on your rerouting) the CI follows controller/function method in its uri calls. So, if you want to call pagelist, you need to have a function within your controller called page_list(or something similar)... so when your uri looks like this http://www.examples.com/pages/page_list, this will call the function page_list within your controller called Pages. Or you can build a routing to have everything after pages passed as variable, but then you may want to have something like http://www.examples.com/pages/page_list/1, this way your pages controller will have a uri array as [page_list]=1 and then you can use if( !empty(page_list) ){ do someting }[/quote] But I'm using the _remap function as described here: http://ellislab.com/codeigniter/user-gui...#remapping So it takes the controller as the first segment, and the other segment are taken as parameters in the _remap function. I can make it as http://example.com/pages/list instead but I'd prefer http://example.com/pages instead since it's easier to type in the address bar.
[eluser]Ki[/eluser]
Yeah... it seems that you got quite a challenge. Try using print to see what uri serves to the controller. One other suggestion is to use isset('something'). If this 'something' is set in uri, then you output function 'something', else you serve the list. I also discovered that if you set re-routing and it looks like this http://example.com/pages/list, it may serve an empty uri array, such as
[eluser]Assim[/eluser]
Thanks mate, it works now. This is how the controller looks like: Code: function _remap($PageSlug) And I added the following in routes.php Code: // Route /pages to /pages/list Now I access this page as http://example.com/pages and http://example.com/pages/list Thanks again for the idea. |
Welcome Guest, Not a member yet? Register Sign In |