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. [CSP-S模拟测试]:u(差分)

    题目背景 $\frac{1}{4}$遇到了一道水题,完全不会做,于是去请教小$D$.小$D$看了一眼就切掉了这题,嘲讽了$\frac{1}{4}$一番就离开了.于是,$\frac{1}{4}$只好来问 ...

  2. Archive.org:互联网档案馆

    Archive.org:互联网档案馆   2009年的最后一天,辞旧迎新,互联网也同样如此,在过往40年的基础上一步步积累发展.对于我们而言很希望通过以往的每个网页.见证和找寻历史,这就是今天所介绍的 ...

  3. php关键字static使用

    php中static关键字使用: 情景1:静态变量 使用static关键字定义静态变量 静态变量:只存在于函数作用域内,也就是说,静态变量只存活在栈中.一般的函数内变量在函数结束后会释放,比如局部变量 ...

  4. English-Useful sentences

    很乐意 pull request. Pleased to pull request. 这个项目现在已经被弃用了. This project is now deprecated. 如你下面看到的,你可以 ...

  5. 用.NET做圣诞节音乐盒

    用.NET做圣诞节音乐盒 我曾经用这个程序送给我女朋友(现老婆)

  6. 动态创建类/ swizzle class

    动态创建类 Class subclass = objc_allocateClassPair(baseClass, subclassName, );//生成,指定父类 //添加方法,变量...一些操作 ...

  7. QTP read or write XML file

    'strNodePath = "/soapenv:Envelope/soapenv:Body/getProductsResponse/transaction/queryProducts/qu ...

  8. Java并发AtomicLong接口

    java.util.concurrent.atomic.AtomicLong类提供了可以被原子地读取和写入的底层long值的操作,并且还包含高级原子操作. AtomicLong支持基础long类型变量 ...

  9. Pikachu漏洞练习平台实验——暴力破解(一)

    概述 一个有效的字典可以大大提高暴力破解的效率 比如常用的用户名/密码TOP500 脱裤后的账号密码(社工库) 根据特定的对象(比如手机.生日和银行卡号等)按照指定的规则来生成密码 暴力破解流程 确认 ...

  10. 正则表达式中(?:pattern)、(?=pattern)、(?!pattern)、(?<=pattern)和(?<!pattern)

    (?:pattern) ()表示捕获分组,()会把每个分组里的匹配的值保存起来,从左向右,以分组的左括号为标志,第一个出现的分组的组号为1,第二个为2,以此类推 (?:)表示非捕获分组,和捕获分组唯一 ...