0
votes

i have problem in codeigniter routes. i want change url from:http://example.com/test/news_details?id=17 to http://example.com/test/funy-url-maker or http://example.com/funy-url-maker

i can make $route dynamicly but it don't work. my code:

$route[rawurlencode("'" . str_replace(' ', '-', $string)) . "'"] = "test/news_details?id=" . $id;

i print route and all route's will be add perfectly, but when i want to open http://example.com/test/funy-url-maker i will be redirect 404 page :( any idea?

note: when i use this as static it work perfectly.like:

$route[rawurlencode('funyNews')] = "test/b_news";

1
please provide how your are defining the $string variable - CodeGodie
require_once (BASEPATH . 'database/DB' . EXT); require_once (BASEPATH . 'helpers/url_helper' . EXT); require_once (BASEPATH . 'helpers/text_helper' . EXT); $db = &DB(); $query = $db -> get('news'); $result = $query -> result(); foreach ($result as $row) { $route[rawurlencode("'" . str_replace(' ', '-', $row->subject)) . "'"] = "test/news_details?id=" . $row->id; } here you are :) - QuestionMark
hey again, seems like they are updating Stack Overflows servers.. - CodeGodie
anyway, can you provide me with the var_dump results of your $result variable? - CodeGodie
there is utf8 character in it (alot) like :[5]=> object(stdClass)#15 (6) { ["id"]=> string(2) "17" ["subject"]=> string(21) "this is gona be right" ["brief"]=> string(8) "testing " ["message"]=> string(4) "test" ["image"]=> string(1) "t" ["tag"]=> string(13) "#Ùناوری" } - QuestionMark

1 Answers

0
votes

ok after all the questions and answers, I think youre looking for something like this:

foreach ($result as $row) {
    $string = rawurlencode(str_replace(' ', '-', strtolower($row->subject)));
    $route[$string] = "test/news_details/$row->id";
}

and your controller:

function news_details($id){
    var_dump($id);
}