[英]SEF URL for categories hierarchy and articles
I've written small framework like code with HMVC architecture using PHP. 我已经使用PHP用HMVC架构编写了类似代码的小型框架。 Below are the sample SEF URLs to access.
以下是要访问的示例SEF URL。
http://domain.com/controller_name/method_name/param1/param2 http://domain.com/folder_name/controller_name/method_name/param1/param2
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 ie, multi-level category structure with set of articles inside, I was not able to make use of above URL.
但是,当我尝试构建一个简单的CMS时,我在另一个类别之内建立了类别,而在其他类别之类的东西中,即具有内部文章集的多级类别结构,我无法使用上述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
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. 谁能帮助我实现上述目标。
if i did not misunderstand you want to query category by sefurl firstly you need to convert data name to sefurl 如果我没有误会您要先按sefurl查询类别,则需要将数据名称转换为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ğ" 现在您可以测试它,例如我的categori名称是“这是一个测试categoriğ”
sefurl($catname);
result is going tobe like "this-is-a-test-categorig" 结果将像“这是一个测试类别”
you can use this for categori id 您可以将其用于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 当您设置新的分类时,在数据库表中像sefurl一样创建新的冒号。将分类器名称转换为sefurl,然后将其设置为sefurl冒号
you can query by sefurl of the categori 您可以通过categori的sefurl查询
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. 通过“ /”解析网址并在categori表中查询该网址后获得“ this-is-a-categor-”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.