Help with proper URL/URI setup |
[eluser]rt30000[/eluser]
I've spent some time trying to get this project halfway working to show my issues better than I can translate: Here is the test URL: CI Project Link As you can see, I just cannot figure out URLs or URIs. I have to use "index.php/page/index/4" (where 4 is the $id of the page to display) rather than a more friendly url. You can click through the pages, all the top level ones are there. The home page, because it has no $id (just goes straight to default controller "page") throws two errors. Ideally, I would like more clear urls and remove the index.php. I tried using .htaccess but I think my server is not accepting it. Is that the first step I need to solve? I really appreciate any help you can lend me...this is my first stab at MVC. Everything on those pages is based off a single template (with sub views), a model and the Page controller. I think i'm beginning to understand the basic concept. Here is my controller just in case it helps. Code: <?php THANKS! rob
[eluser]Dready[/eluser]
Hello, can you tell us what's not working, or what you trying to achieve ?
[eluser]xwero[/eluser]
If .htaccess files are not allowed by the server than there is nothing you can do to remove the index.php. For the $id as a function argument just make it optional by adding a default value.
[eluser]rt30000[/eluser]
Thank you xwero. I know for a fact I tried a default value without any luck, but I must have had anopther error somewhere. I tried it again and it worked beautifully. I am still working on getting .htaccess working to remove the index.php, which shouldn't be a huge issue. The biggest thing right now, is understanding how to change the urls from "index.php/page/index/2" to something like "index.php/products". I will be having subdirectories too, such as "index.php/products/cheese" and "index.php/products/cheese/glossary". I am at a loss at how to do this. I looked into something called routing but didn't have much luck. Is that the right method? Thanks a ton! Im liking CI more and more as I dig deeper into it and mvc concepts.
[eluser]xwero[/eluser]
Yes routing is one way to go. I think products will be a controller but for example the glossary route can be Code: $route['(products)/([a-z\-]+)/(glossary)'] = '$1/$3/$2';
[eluser]rt30000[/eluser]
Yikes. I need to learn more about regular expressions, etc. That goes way over my head to understand and use it properly. So do I need a different controller for each page that will have subpages? Right now I just use a single page controller "page.php" (shown at top of this thread) that populates the page with the correct data. Perhaps the next step for me is getting the top-level pages' URL/URI working and displaying correctly, and then attempting the subdirectories? Is this even the best way of setting my site up or am I missing something?
[eluser]rt30000[/eluser]
I think Im making progress! I moved the _setup_page() function to the actual model which makes creating a bunch of controllers not duplicate a ton of code. I think i've made a breakthrough! http://www.new.gffarms.com/ Now the pages' url shows at least the category they belong in! Now I think I can figure out how to do subpages, they would just be function inside the respective controller (such as "index.php/products/2" could be a cheese page. Right? I will worry about removing index.php down the road, I dont think thats a major issue. This is restoring faith that I can figure this out. Rob |
Welcome Guest, Not a member yet? Register Sign In |