Joomla!-开源天空

2008-12-05


自定义URL (上)

E-mail

简介

Joomla! 1.5生成部分已经彻底重构了.Joomla!可以生成和解析任何格式的url,包括那些可读性的url。另一项改进是即使在不是apache的mod_rewrite服务器上,Joomla的这部分功能仍然可以运行。

Joomla! is now capable of creating and parsing URLs in any format, including human readable URL‘s. Another improvement is that this still works even if Joomla! runs a server other than Apache with the mod_rewrite module.

下面是一个例子,第一个是没有mod_rewrite的情况下生成的,第二个是采用mod_write生成的。

http://www.example.com/index.php/the-news/1-latest-news/1-welcome-to-joomla
http://www.example.com/the-news/1-latest-news/1-welcome-to-joomla


别名(短名称)


首先要生成alias,这个alias用在URL中,这个alias是符合URI规范的,也就是说相应的UTF-8字符被替换为ASCII-7 ,空格用连词符替代,等等。

The alias 也可以由用户定义,但是必须保证符合uri的规范,最好是在保存的时候采用 JTable::check()进行检查。请看下面的例子:

function check()
{
       jimport( 'joomla.filter.output' );
       $alias = JOutputFilter::stringURLSafe( $this?->title );
       if(empty( $this?->alias ) || $this?->alias === $alias ) {
               $this?->alias = $alias;
       }
       /* All your other checks */
       return true;
}

如果alias字段为空或者符合uri规范,才能使用这个alias.

 

The Slug(how to translate)

回过来看我们的例子“slug” - “1-welcome-to-joomla”有两部分,第一部分是文章的唯一编号,第二部分是alias,中间是连词符,这两个部分通常在查询的时候被组合在一起。


$query = 'SELECT a.*'.
        ' CASE WHEN CHAR_LENGTH (a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'.
        [...];After this step the slug is used instead of the id.


 



收藏此文章:
Digg! Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码