Help with planning a CI project |
[eluser]invision[/eluser]
Hi, I'm planning to build a small site for a business and would really love to do it in CodeIgniter. It's a fairly basic site which, in time, I hope to content-manage with a CMS. My Site Map: Quote:Home Now, I just wonder how the best way of organising this in CodeIgniter would be? Home and About pages would just be taking static content from a 'pages' table in my database and outputting it. However, Vacancies and News would list data from the vacancies and news tables respectively. Would I create models for Pages, Vacancies and News. And then create a Controller for each of these too? Ultimately, I'd love my web url's to be like: www.example.com/about/our-team www.example.com/news/news-entry-slug If anyone can give me a head start or any pointers, I'd super appreciate it. Many thanks.
[eluser]eoinmcg[/eluser]
I'd do it with 3 controllers: pages as default controller news controller vacancies controller the latter 2 are fairly self explanatory. but pages may need a bit more of a breakdown: 1. in routes.php set default controller as so Code: $route['default_controller'] = "pages"; 3. to get rid of http://www.example.com/pages/about/etc/etc you'll need to modify the router class, specifically the _validate_request(), method. there's plenty of example on the forum about this but give me a shout if you get stuck. good luck!
[eluser]invision[/eluser]
Many thanks for the speedy reply eoinmcg! Prepare yourself for the response Just to get me rolling....how does the following look: Code: // Page Controller Models Code: // Pages Model Views Code: // Vacancies View Template View would just be something like: Code: <div id="mainContent"> Does this look like a good start? I realise it's a lot to take in at first, but am I heading in the right direction? I really value any feedback for this. Very new to CodeIgniter but excited for the project. Thank you.
[eluser]eoinmcg[/eluser]
sure, looks fine, after a quick glance.... experience is the best teacher, so get hacking!
[eluser]invision[/eluser]
Eeeeek. Scared in a good way Busy night ahead for me. I may be back. Thanks again.
[eluser]invision[/eluser]
So far, so-so I'm going to focus on Pages in this reply. Controller: Code: <?php Model: Code: <?php Now going to: http://www.site.com/index.php/page/ shows my Home Page perfectly. However I have created a page 'Location' as a record in my 'pages' table. I was hoping to visit this by going to http://www.site.com/index.php/page/about-us/location/ but sadly this doesn't work. I get a 404 Error. Could someone guide me where I'm going wrong with the above code? I'm new to this, so as much help as you can give is so much appreciated. Many thanks.
[eluser]theprodigy[/eluser]
Code: function pages($slug){ Your url of http://www.site.com/index.php/page/about-us/location/ is passing about-us into that parameter. So your model is looking for the record that has about-us as the slug EDIT: Actually, I'm incorrect in the above. Sorry. Your default is working because it's calling the index function. In order to get the above method to work, you would need a url of something like http://www.site.com/index.php/page/pages/location/. You would need to call the method, then pass in the parameter
[eluser]invision[/eluser]
Aaaah good call. However, I still get a 404 Error when I try to load 'about-us' on it's own. 'about-us' is the value of a slug in my sql table. Would I need a new function if I was to retrieve 2 slugs? Or would it make more sense just to retrieve the ID of the record and rewrite the URL some other way? Thanks
[eluser]theprodigy[/eluser]
I just editted my reply. Make sure you refresh you page ;-)
[eluser]invision[/eluser]
Wow, got it in one Thank you for your help. It's now displaying under: http://www.site.com/index.php/page/pages/location/ However, I'd like to change this to be: http://www.site.com/index.php/page/about-us/location/ Would this be an easy fix to make? |
Welcome Guest, Not a member yet? Register Sign In |