0

I've written small framework like code with HMVC architecture using PHP. Below are the sample SEF URLs to access.

http://domain.com/controller_name/method_name/param1/param2 http://domain.com/folder_name/controller_name/method_name/param1/param2

Above are fine and working with the fixed kind of data. But when I tried building a simple CMS, where I've category inside another category and other and so on i.e., multi-level category structure with set of articles inside, I was not able to make use of above URL. I want something like

http://domain.com/category-name/sub-category-name/sub-sub-category-name http://domain.com/category-name/sub-category-name/article-name

Can anyone help me with snippet to achieve above.

Getz
  • 3,983
  • 6
  • 35
  • 52
Sailesh Jaiswal
  • 187
  • 1
  • 17

1 Answers1

0

if i did not misunderstand you want to query category by sefurl firstly you need to convert data name to sefurl

function sefurl($s){ 
     $s=trim($s);
     $tr = array('ş','Ş','ı','I','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç','(',')','/',':',',');

     $eng = array('s','s','i','i','i','g','g','u','u','o','o','c','c','','','-','-','');

     $s = str_replace($tr,$eng,$s);



     $s = preg_replace('/&.+?;/', '', $s);

     $s = preg_replace('/\s+/', '-', $s);

     $s = preg_replace('|-+|', '-', $s);

     $s = preg_replace('/#/', '', $s);

     $s = str_replace('.', '.', $s);

     $s = trim($s, '-');

     $s = htmlspecialchars(strip_tags(urldecode(addslashes(stripslashes(stripslashes(trim(htmlspecialchars_decode($s))))))));

     return $s;

        }

now you can test it for example my categori name is "this is a test categoriğ"

sefurl($catname);

result is going tobe like "this-is-a-test-categorig"

you can use this for categori id

create a new colon in your DB table like sefurl when you set a new categoriy convert the categori name to sefurl and than set it to sefurl colon

you can query by sefurl of the categori

http://yourdomain.com/categori/this-is-a-categor-/

parse url by "/" and get "this-is-a-categor-" after that query it in your categori table.

Ahmet ATAK
  • 342
  • 2
  • 13