-3

i want to change my codigniter url which looks like

http://dev.hello.com/about/updateVision/9 to http://dev.hello.com/about/updateVision/this-is-test-edit/ i have no idea how to make looks like that anyone can help please thanks !

  • If you can , then user Laravel – voila Jan 28 '15 at 08:45
  • take a look at http://stackoverflow.com/questions/10241806/pretty-url-setting-in-codeigniter – Rooneyl Jan 28 '15 at 08:47
  • ok i can send title /name if there is a single word like America but what should i do if my title is long and i need (-) between every single word? like test-comments-heelo-thi-is-test-commets/ – Santosh Rana Jan 28 '15 at 09:01
  • @SantoshRana the linked answer contains a custom router class that will convert hyphens to underscores. You can create the SEO link by using $url_title = url_title($title, 'underscore'); – Rooneyl Jan 28 '15 at 09:07

1 Answers1

0

This all depends on you database structure. I would introduce a field called reference or slug. This will contain a unique string for your record. When creating the record you can use the url_title function to remove spaces as mentioned by @Rooneyl

This reference must be unique so I would create a function that creates a reference in a loop, checks it against the database. When it returns false, it is unique.

public function unique_reference($name)
{
    $name = trim(strtolower($name));
    $unique_reference = url_title($name);
    $counter = '';
    do {
        $result = $this->db->select('id')
                   ->from('your_table')
                   ->where('reference', $unique_reference)
                   ->get()->row();

        if ($result)
            $counter++;

        $unique_reference = url_title(trim("{$name} {$counter}"));
    } while ($result);

    return $unique_reference;
}

You can then retrieve record using this unique value

Richard Merchant
  • 983
  • 12
  • 10