Welcome Guest, Not a member yet? Register   Sign In
String as an URL
#10

[eluser]Phil Sturgeon[/eluser]
These posts will only confuse the man!

georgerobbo: Doing this is very similar to working with ID's. Normally you create a database record then use the ID number in the URL to fetch the content. Using a slug is exactly the same, but ofc first it needs to be made.

Code:
$this->db->set('slug', url_title($this->input->post('title')));
$this->db->set('title', $this->input->post('title'));
$this->db->insert('articles');

That will set it for your INSERT column, but is only one of many ways to achieve this. Pick your preferred syntax.

Then when you want to view an article, just do this:

Code:
<?php
class Blog extends Controller {
  
  function view_article($slug)
  {
    $this->db->where('slug', $slug);
    $this->db->get();
  }
}
?>

Again a rather rough demo, that ofc should be in a model, but blog/view_article/some-title will now work fine. Shorten that with some routes and you are away!


Messages In This Thread
String as an URL - by El Forum - 09-06-2009, 09:50 AM
String as an URL - by El Forum - 09-06-2009, 02:03 PM
String as an URL - by El Forum - 09-06-2009, 02:05 PM
String as an URL - by El Forum - 09-07-2009, 12:26 PM
String as an URL - by El Forum - 09-07-2009, 04:05 PM
String as an URL - by El Forum - 09-07-2009, 05:14 PM
String as an URL - by El Forum - 09-08-2009, 06:24 AM
String as an URL - by El Forum - 09-08-2009, 06:28 AM
String as an URL - by El Forum - 09-08-2009, 07:07 AM
String as an URL - by El Forum - 09-08-2009, 07:55 AM
String as an URL - by El Forum - 09-09-2009, 12:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB