查看完整版本: kohana文档翻译(URLS)

星期八 2008-7-16 15:25

kohana文档翻译(URLS)

在Kohana中URL同分段组成,典型的URL:http://localhost/control/action/arg1/arg2 ,各分段依次对应控制器,控制器方法,方法参数,
[indent]例如:http://localhost/index.php?/articles/edit/1/my-first-article
[/indent][list][*]articles(控制器)[*]edit(方法)[*]1(第一个参数)[*]my-first-article(第二个参数)[/list]这会对应控制器articles,关于 [url=http://www.8ther.com/?p=1][color=#63dbf5]Controllers[/color][/url]

第二个分段对应application/controllers/articles.php中的Articles_Controller类的edit方法,如果第二分段不存在,它将会调用index() 方法,如果第二分段的方法不存在会调用 _default() 方法或者转向404页面
第三,第四分段传递给edit方法,比如说 edit($id,$title)
Example:
[code=PHP]<?php
class Articles_Controller extends Controller {
   function __construct(){
        parent::__construct();

    }
    function index()
    {

    }
    function edit($id,$title){
       //get the article from the database and edit it
       echo $id;
       $this->load->view('articles/edit');
    }
}
?>[/code]


[b]URL重写[/b]
默认情况下,Kohana urls中含有index.php,这看起来不太友好,和对搜索引擎不利.看下面两个URL的区别:
[indent]http://localhost/index.php?/articles/edit/1/my-first-article
// or the same URL with url rewriting on
http://localhost/articles/edit/1/my-first-article
[/indent]后一个更加友好,对搜索引擎更有利,下面的URL对某些系统会更有益.
[indent]http://kohanaphp.com/tutorials/remove_index.html
[url]http://forumarchive.kohanaphp.com/index.php/topic[/url],246.0.html
[/indent][b]后缀:[/b]在Kohana中,你可以为你的URL设置一个后缀.
[indent]http://localhost/index.php?/articles/edit/1/my-first-article.html
[/indent]可以在application/config/config.php文件中修改url_suffix
[b]允许的字符[/b]
你可以在config/routes.php文件中修改允许的字符
[b]查询字符串和GET方法支持[/b]
查询字符串和GET在Kohana中是可选的,你可以简单的在URL后附加?var=value ,当global_xss 开启时,传入的参数对会被输入类库进行检测和过滤
页: [1]
查看完整版本: kohana文档翻译(URLS)