用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3914|回复: 0
收起左侧

kohana文档翻译(URLS)

[复制链接]
发表于 2008-7-16 15:25:17 | 显示全部楼层 |阅读模式
在Kohana中URL同分段组成,典型的URL:http://localhost/control/action/arg1/arg2 ,各分段依次对应控制器,控制器方法,方法参数,
例如:http://localhost/index.php?/articles/edit/1/my-first-article
  • articles(控制器)
  • edit(方法)
  • 1(第一个参数)
  • my-first-article(第二个参数)
这会对应控制器articles,关于 Controllers

第二个分段对应application/controllers/articles.php中的Articles_Controller类的edit方法,如果第二分段不存在,它将会调用index() 方法,如果第二分段的方法不存在会调用 _default() 方法或者转向404页面
第三,第四分段传递给edit方法,比如说 edit($id,$title)
Example:
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');
    }
}
?>
复制代码



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

本版积分规则