Welcome Guest, Not a member yet? Register   Sign In
Creating static pages
#1

[eluser]Maglok[/eluser]
At the moment I have this elaborate system of stuff that is starting to work quite nicely. The site itself will be needing actual pages though, the static kind. Now I've never really done those in CodeIgniter. At the moment there is a 'simple' idea in my head and I dunno if it is smart to do it like that or if there is an easier way.

I create a controller 'content' I pass a 'id' in the url to determine what page is loaded. I create a view that puts a textarea from the database (with the id) in the template page and thus generate the content. Add in a title, some keywords, the works.

You'd go to a page like this:

Code:
http://www.domain.com/content?id=235

My main gripe with this concept is readability. CodeIgniter works with readable url's. Any suggestions so I don't have to reinvent the wheel here?
#2

[eluser]Cro_Crx[/eluser]
Try storing a unique "uri" field in the database. That way you could access pages using a url like this:

Code:
http://www.domain.com/content?uri=name-of-page

If you wanted the URL a bit nicer you could use uri's instead of url parameters, so then you could neaten it to

Code:
http://www.domain.com/name-of-page/

Have a look through the user manual as it shows how to do this!
#3

[eluser]Maglok[/eluser]
You mean this: http://ellislab.com/codeigniter/user-gui...uting.html ?

It isn't really an easy thing to do.

I also just thought of 'what if there is more then one 'directory''?

Example: You have a page 'DVDs' and then under the page you want 'Star Wars' for example. You'd want a url like this:

Code:
http://www.domain.com/dvds/star-wars/

So just using 1 identifier is not going to be enough.
#4

[eluser]Phil Sturgeon[/eluser]
Doing this with routing is a nightmare for the reason Maglok points out.

There are several ways around this:

1.) Define all existing controllers in a route, then put your "catch all" routing rule to pages controller at the bottom.

2.) Extend the router, so right after all the "is this a controller, is this a sub-directory", etc checks and before the show_404(), you set the router to look at the page controller.

3.) Use Modular Separation with its awesome new $route['404'] = 'pages'; route.

Let me know which sounds nicer and I can explain it in more detail.
#5

[eluser]Maglok[/eluser]
I am rather new to changing routing on this scale.

The way I see it I have two different types of content: The dynamic kind and the static kind. I have no problem setting up dynamic content, because they all get their own controllers and views, etc. The static content is the 'problem' in that I don't want to have to make a controller for each and every static page I need.

So that means I need to use a variable to determine what page is loaded by a controller using data in a database. And I am tripping up on the concept of 'implementing' directories.

Mabye a better question is: How would you do it?
#6

[eluser]rogierb[/eluser]
I'd go for extending the router class (option 2).
This feels like the best way to go(if you are not using Modular Separation)

This way you can create a page controller with _remap() that serves static pages when needed or routes to the 404


edit: Must...learn...to...type...
#7

[eluser]Maglok[/eluser]
Been givig it some thought. Extending core classes is always tricky, since then you gotta understand the code in the coreclass.

First I figure an example of what I want:

Lets say I have 4 pages and each static page is kept in the database with an ID:

1 - About
2 - Links
3 - Info
4 - Pie

The base url for those would be:
Code:
http://www.mydomain.com/controller/method/var

So for the About page it would be:
Code:
http://www.mydomain.com/content/static/about

Ideally I'd want:
Code:
http://www.mydomain.com/about

I can set up those rules manually, but I want it to be done automatically. So then I need to find a way to do that dynamically. Of the three presented options, 2 and 3 sound like the least amount of overhead. I gotta admit I don't really know anything about 'Modular Seperation' so that's a prob. If it has to do with HMVC, then I rather not go there I am perfectly happy with MVC.

Of course this would not even tackle the subdirs issue, but baby steps right?
#8

[eluser]rogierb[/eluser]
Quote:http://www.mydomain.com/about

It would tackle the subdirs issue as far I can see.
If you create one controller for all your static pages, you can account for everything, probably in one method
Read up on _remap() and maybe _call().

And with option 2 you don't need to setup routing, all pages it cannot find are handled by your controller.
#9

[eluser]Phil Sturgeon[/eluser]
Just make a MY_Router.php, copy _validate_request() and right at the bottom replace show_404($segments[0]) with:

Code:
// Not a sub-dir or controller, now go to content and try there
        $this->set_class('content');
        return array('content', 'static', $segments[0]);
#10

[eluser]Maglok[/eluser]
I will look into it. Already thanks for all the help so far.




Theme © iAndrew 2016 - Forum software by © MyBB