php 后台转发和重定向的区别及kohana框架当前url加参数方式
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加参数方式的更多相关文章
- Servlet中转发和重定向的区别
Servlet中页面的跳转有两种方式:转发和重定向. 1.转发和重定向的区别 ①转发是服务器行为,重定向是客户端行为. ②转发是浏览器发生了一次请求,重定向至少是两次请求. ③转发地址栏中的url不会 ...
- servlet之转发与重定向的区别
转发(服务器端跳转): 一次请求 <jsp:forward> request.getRequestDispatcher("new.jsp").forward(requ ...
- jsp内置对象 转发与重定向的区别
jsp 内置对象 转发与重定向的比较 重定向和转发有一个重要的不同:当使用转发时,JSP容器将使用一个内部的方法来调用目标页面,新的页面继续处理同一个请求,而浏览器将不会知道这个过程. 与之相反,重 ...
- Java中转发与重定向的区别
转发与重定向的区别 转发是服务器行为,重定向是客户端行为 1.转发在服务器端完成的:重定向是在客户端完成的2.转发的速度快:重定向速度慢3.转发的是同一次请求:重定向是两次不同请求4.转发不会 ...
- SERVLET API中转发与重定向的区别?
SERVLET API中转发与重定向的区别? 1.转发(forward方法) 转发仅是容器中控制权的转向,在客户端浏览器地址栏中不会显示出转向后的地址. 转发是服务器请求资源,服务器直接访问目标地址的 ...
- Java 请求转发和重定向的区别以及JavaWeb三大作用域
三大作用域以及转发和重定向 学习总结 1. 转发和重定向 转发 重定向 转发和重定向的区别: 什么时候用转发什么时候用重定向 三大作用域 作用域类型 作用域方法 如何选择作用域 总结 学习总结 1. ...
- http页面转发和重定向的区别
一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp").forward(request ...
- [drp 7]转发和重定向的区别
导读:类似于response.sendRedirect(request.getContextPath()+"/servlet/item/SearchItemServlet");和r ...
- Servlet & JSP - 转发与重定向的区别
本文转载自:http://blog.csdn.net/kobejayandy/article/details/13762043 转发 转发的原理,可以通过下图展示: 浏览器的请求发送给组件 1,组件 ...
随机推荐
- 教你建立SQL数据库的表分区
1)新建一个数据库 2)添加几个文件组 3)回到“常规”选项卡,添加数据库文件 看到用红色框框起来的地方没?上一步中建立的文件组在这里就用上了.再看后面的路径,我把每一个文件都单独放在不同的磁盘上,而 ...
- git分支merger
- delphi 半透明窗体类
{******************************************************************************* 半透明窗体控件 版本:1.0 功能说明 ...
- [CSP-S模拟测试]:字符消除2(hash+KMP)
题目背景 生牛哥终于打通了“字符消除”,可是他又被它的续集难倒了. 题目传送门(内部题52) 输入格式 第一行$n$表示数据组书.接下来每行一个字符串.(只包含大写字母) 输出格式 每组数据输出一个$ ...
- 《图解设计模式》读书笔记6-2 Chain of Responsibility模式
目录 1. 简介 2. 示例程序 类图 代码 3. 模式的角色和类图 角色 类图 4. 思路拓展 1. 简介 Chain of Responsibility模式是责任链模式,模式的核心就是转移责任.就 ...
- 让Tomcat支持php
在服务器上php的安装:1.下载php-4.4.2 for windows的压缩包2.解压缩到D:\software\php4423.将D:\software\php442增加到环境变量PATH中4. ...
- Python笔记(十)_迭代器与生成器
迭代 用for...in来遍历一个可迭代对象的过程就叫迭代 可迭代对象:列表.元组.字典.集合.字符串.生成器 可以使用内置函数isinstance()判断一个对象是否是可迭代对象 >>& ...
- 【html】 两栏对比网页,同时滚动
有的时候需要左右对比环境,而且希望能同时滚动,如下这么拼接就可以了 <html> <head><meta http-equiv="content-type&qu ...
- centosifcfg-eth0文件内容为空
虚拟机安装好CentOS 6系统后,发现ip在每次重启后都会还原,用ifconfig查看是有eth0网卡的(也有可能只有回环网卡lo),于是查看eth0网卡配置文件,发现在 /etc/sysconfi ...
- MybatisPlus自动填充公共字段的策略
背景:数据库中多个表有时间字段,并且字段名一致 需求:该时间字段由MybatisPlus自动插入和更新,业务代码无需处理 方法: 一.创建基础实体[BaseEntity],定义需要处理的公共字段(创建 ...