Welcome Guest, Not a member yet? Register   Sign In
Creating dynamic Views
#1

[eluser]Higher Logic[/eluser]
Here's a scenario:

I have a blog. My URL structure looks like this:

http://www.domain.com/blog/

With CI, I'm going to have a view for this. Then let's say I have an entry:

http://www.domain.com/blog/my-first-post/

I've been trying to think of a way to get a dynamic URL segment (entry title) to be positioned after a view instead of doing something like this:

http://www.domain.com/blog/view/my-first-post/

Normally, I would set this all up like so:

http://www.domain.com/blog/index.php?slug=my-first-post

Where the index.php file would check for the $_GET['slug'] value to determine the post to grab from the database and output, and if no $_GET['slug'] variable existed, it would output the standard blog listing with a list of entries and excerpt of their content.

So my question is, how do you set something like this up with CI without setting up another view?
#2

[eluser]alpar[/eluser]
if i get this right, you want to set up a blog made with CI and use it in a bigger site? You put CI in the folder blogs, make a controller called view, and a method called show (you can call it something else), you give one parameter to the method with will be the title of your blog.
then you add
Code:
$route['view/(:any)'] = "view/show/$1"

play around with these, i don't say it's working out of the box, but this is one way that you can do it.
#3

[eluser]Higher Logic[/eluser]
Ah, that looks like it will do it. Not creating a blog, but that was just a scenario that many have probably seen before.

$route['blog/(:any)'] = "blog/$1";

And if there was not anything, the view for the blog's index would show up.

Edit: Ok, that totally makes sense now and works perfectly. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB