1、重定向是浏览器行为,浏览器地址有变化;转发是后台服务器完成, url地址不变化。

2、kohana获取URL

当前url是http://soyoung.kohana.com/blog/add?id=3

var_dump(Url::site('blog/add', NULL, FALSE) );               打印string '/blog/add' (length=9)

var_dump(URL::query());                                                    打印string '?id=3' (length=5)

E:\html\kohana\modules\pagination\classes\kohana\pagination.php

	public function url($page = 1)
{
// Clean the page number
$page = max(1, (int) $page); // No page number in URLs to first page
if ($page === 1 AND ! $this->config['first_page_in_url'])
{
$page = NULL;
} switch ($this->config['current_page']['source'])
{
case 'query_string': //不带之前url参数
return URL::site(Request::current()->uri(),NULL,FALSE).URL::query(array($this->config['current_page']['key'] => $page)); case 'route': //带上之前url参数
return URL::site(Request::current()->uri(array($this->config['current_page']['key'] => $page)),NULL,FALSE).URL::query();
} return '#';
}

  E:\html\kohana\application\classes\Controller\Blog.php

    //列表分页
public function action_index() {
//first calc average count
$count = model::factory('Post')->posts_count();
//you can change items_per_page
$num = 2;
//you can configure routes and custom routes params
$pagination = Pagination::factory(array(
'total_items' => $count,
'items_per_page' => $num,
//'current_page' => Request::current()->param("page"),
'current_page' => array('source' => 'route', 'key' => 'page'),
)
);
$posts_list = model::factory('Post')->posts_list($pagination->items_per_page, $pagination->offset);
$view = View::factory('blog/list')->set('posts', $posts_list)->set('pagination',$pagination);
$view->render();
$this->response->body($view);
}

 kohana隐藏index.php 

步骤1:.htaccess

# Turn on URL rewriting
RewriteEngine On # Installation directory
rewriteBase / # Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files> # Protect application and system files from being viewed
#RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteRule ^(application|modules|system)/ - [F,L] # Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d # Rewrite all other URLs to index.php/URL
#RewriteRule .* index.php/$0 [PT]
RewriteRule .* index.php [L]

步骤2:Url::site('blog/add', NULL, FALSE)

	/**
* Fetches an absolute site URL based on a URI segment.
*
* echo URL::site('foo/bar');
*
* @param string $uri Site URI to convert
* @param mixed $protocol Protocol string or [Request] class to use protocol from
* @param boolean $index Include the index_page in the URL
* @return string
* @uses URL::base
*/
public static function site($uri = '', $protocol = NULL, $index = TRUE)
{
// Chop off possible scheme, host, port, user and pass parts
$path = preg_replace('~^[-a-z0-9+.]++://[^/]++/?~', '', trim($uri, '/')); if ( ! UTF8::is_ascii($path))
{
// Encode all non-ASCII characters, as per RFC 1738
$path = preg_replace_callback('~([^/]+)~', 'URL::_rawurlencode_callback', $path);
} // Concat the URL
return URL::base($protocol, $index).$path;
}

  

步骤3:bootstrap.php

 * - string   base_url    path, and optionally domain, of your application   NULL
* - string index_file name of your index file, usually "index.php" index.php
* - string charset internal character set used for input and output utf-8
* - string cache_dir set the internal cache directory APPPATH/cache
* - integer cache_life lifetime, in seconds, of items cached 60
* - boolean errors enable or disable error handling TRUE
* - boolean profile enable or disable internal profiling TRUE
* - boolean caching enable or disable internal caching FALSE
* - boolean expose set the X-Powered-By header FALSE
*/
Kohana::init(array(
'base_url' => '/',
'index_file' => '',
));

  

php 后台转发和重定向的区别及kohana框架当前url加参数方式的更多相关文章

  1. Servlet中转发和重定向的区别

    Servlet中页面的跳转有两种方式:转发和重定向. 1.转发和重定向的区别 ①转发是服务器行为,重定向是客户端行为. ②转发是浏览器发生了一次请求,重定向至少是两次请求. ③转发地址栏中的url不会 ...

  2. servlet之转发与重定向的区别

    转发(服务器端跳转):  一次请求 <jsp:forward> request.getRequestDispatcher("new.jsp").forward(requ ...

  3. jsp内置对象 转发与重定向的区别

    jsp 内置对象  转发与重定向的比较 重定向和转发有一个重要的不同:当使用转发时,JSP容器将使用一个内部的方法来调用目标页面,新的页面继续处理同一个请求,而浏览器将不会知道这个过程. 与之相反,重 ...

  4. Java中转发与重定向的区别

        转发与重定向的区别 转发是服务器行为,重定向是客户端行为 1.转发在服务器端完成的:重定向是在客户端完成的2.转发的速度快:重定向速度慢3.转发的是同一次请求:重定向是两次不同请求4.转发不会 ...

  5. SERVLET API中转发与重定向的区别?

    SERVLET API中转发与重定向的区别? 1.转发(forward方法) 转发仅是容器中控制权的转向,在客户端浏览器地址栏中不会显示出转向后的地址. 转发是服务器请求资源,服务器直接访问目标地址的 ...

  6. Java 请求转发和重定向的区别以及JavaWeb三大作用域

    三大作用域以及转发和重定向 学习总结 1. 转发和重定向 转发 重定向 转发和重定向的区别: 什么时候用转发什么时候用重定向 三大作用域 作用域类型 作用域方法 如何选择作用域 总结 学习总结 1. ...

  7. http页面转发和重定向的区别

    一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp").forward(request ...

  8. [drp 7]转发和重定向的区别

    导读:类似于response.sendRedirect(request.getContextPath()+"/servlet/item/SearchItemServlet");和r ...

  9. Servlet & JSP - 转发与重定向的区别

    本文转载自:http://blog.csdn.net/kobejayandy/article/details/13762043 转发 转发的原理,可以通过下图展示: 浏览器的请求发送给组件 1,组件 ...

随机推荐

  1. php strncmp()函数 语法

    php strncmp()函数 语法 作用:比较字符串前n个字符,区分大小写 语法:strncmp(string1,string2,length)直线电机品牌 参数: 参数 描述 string1 必须 ...

  2. txt操作

    C#解决读写包含汉字的txt文件时乱码的问题 C#解决读写包含汉字的txt文件时乱码的问题 当我们用System.IO.StreamReader读取包含汉字的txt文件时,经常会读出乱码(Stream ...

  3. Ant Design Pro (中后台系统)教程

    一.概念:https://pro.ant.design/docs/getting-started-cn(官方网站) 1.Ant Design Pro 是什么:  https://www.cnblogs ...

  4. Linux后台执行脚本 &与nohup

    Linux后台执行脚本的方式: 0.脚本代码 [root@VM_1_3_centos apps]# cat test.php <?php sleep(5); echo "hello w ...

  5. 按回车键切换input鼠标光标

    function focue(){ if(event.keyCode==13){//回车键的键值13 event.keyCode=9;//tab键的键值9 } }

  6. 在虚拟机的Linux系统下安装wineqq

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 本文参考教程:http://www.ubuntukylin.com/ukylin/forum.php?mod=viewthread& ...

  7. mac 支持rz sz

    安装 lrzsz brew install lrzsz 配置 iTerm2 安装完成后我们需要在 iTerm2 中使用的话,还需要一些配置 进入到 /usr/local/bin 目录下,下载两个脚本文 ...

  8. <每日一题>题目4:for循环套生成器的面试题

    题目: def add(n,i): return n+i def test(): for i in range(4): yield i g = test() for n in [1,10,5]: g ...

  9. Yii 1.1 cookie删不掉

    我的cookie是这样设置的: $cookie = new CHttpCookie('username','Jack'); $cookie->expire = time()+60*60*24*3 ...

  10. (十二)Bind读取配置到C#实例

    继续上一节的,接下来用Options或者Bind把json文件里的配置转成C#的实体,相互之间映射起来.首先新建一个asp.net core mvc项目OptionsBindSample Startu ...