Welcome Guest, Not a member yet? Register   Sign In
creating simple "about us" or "faq" pages...
#1

[eluser]tomdelonge[/eluser]
How do you approach this?

I want:
example.com/aboutus/
example.com/faq/
example.com/contactus/

but I don't just want to have those controllers and have the index method call a view named the same thing. (I think it's dumb to have 3 separate controllers for a simple task).

So I thought I could just use some routing in my route config file and make /aboutus/ go to pages/aboutus, etc...
That way the pages controller takes care of it all.

So, two questions:
1. Does routing slow a lot down? (It seems like every request would have to be gone through to see if it matches any in the entire list)
2. What is your approach to creating "simple pages"

Thanks.
#2

[eluser]JayTee[/eluser]
[quote author="tomdelonge" date="1247723691"]1. Does routing slow a lot down? (It seems like every request would have to be gone through to see if it matches any in the entire list)[/quote]
Routing gets loaded every time - with your example, any slowdown would be negligible if at all. Remember; the routes are defined as array keys - so the lookup isn't a "loop" in the background, it's an array_key_exists() function call that's very fast.

[quote author="tomdelonge" date="1247723691"]2. What is your approach to creating "simple pages"[/quote]
I'm lazy - I just have a "home" controller with all the simple page methods:
http://www.example.com/home/faq
http://www.example.com/home/about
http://www.example.com/home/contact

If you really want one controller for the simple pages, routing really is your best bet.
#3

[eluser]sophistry[/eluser]
hi tomdelonge...

yes, you need routing... no it doesn't slow it down too much. (other things like bad database design or wasteful SQL will slow your code down way more)

you could do it with a simple route like:
Code:
$route['(faq|about|contact)'] = 'pages/$1';

OR... for a more complete approach... i set up a solution to make "simple pages" actually simple. just put your pages in a views sub-directory and CI will load them.

check out site_migrate in the wiki.

cheers.
#4

[eluser]Kepler[/eluser]
You could also use a generic controller that every page uses. Pass all pages to the generic controller using URL rewriting. You need to modify the section of your .htaccess file (if you have one) to look like:

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/generic/index/$1 [L]

This passes all pages through a controller called Generic and calls the index() method passing the page name as a parameter:

Code:
<?php
class Generic extends Controller {

    function Generic()
    {
        parent::Controller();
    }

    function index($page='')
    {
...




Theme © iAndrew 2016 - Forum software by © MyBB