Blog system....posts |
[eluser]Adam Griffiths[/eluser]
Hey, I've got a blog system that I am building on top of CI. So far it is really simple, I'm just pulling data out of the database and displaying it in a view. But I am not showing all my posts, just the introduction. How would I make it so I can link to a page, have the URL the same as the title but with '-' instead of spaces (I know there is already a function for this so that won't be a problem) but grab only that post from the database and display it? So if I have a post called CodeIgniter rocks my socks I can go to www.myurl.com/index.php/post/codeigniter-rocks-my-socks/ and display the post from the databse? The only part I'm having trouble with is how do I let CI know which post to pull from the database? I had the idea of using the function to make a new string (i.e. codeigniter-rocks-my-socks) for each post then pulling that, but I've no idea how CI would know that the string is in the URL. I would usually use $_GET but obviously I can't with CI. Any comments will help greatly. Thanks, Adam Griffiths
[eluser]xwero[/eluser]
You have to create an extra field that stores the to url segment transformed title and you select the blog post based on that field.
[eluser]GSV Sleeper Service[/eluser]
I've done exactly that, I save the title using the url_title helper in the database as 'slug' and my post method looks like this Code: function post($slug) { |
Welcome Guest, Not a member yet? Register Sign In |