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,组件 ...
随机推荐
- 圆周率Pi是如何计算出来的
object SparkPi { def main(args: Array[String]) { val spark = SparkSession .builder .appName("Sp ...
- ElasticSearch学习文档2018.11
1 Elasticsearch安装 1.1 ES6.0版本安装head插件 1.1 下载head插件 下载地址:https://github.com/mobz/elasticsear ...
- 10.21 crond定时任务练习
1.玩crond必须以下任务开启 [root@wen ~]# chkconfig --list crond crond 0:off 1:off 2:on ...
- 如何保留小数点后N位?
2014年10月17日09:48:39 在做项目中遇到的,要把想显示的数据进行规定小数位的保留,下面写一下用过的方法: 1. BigDecimal 方法(我做项目的时候用的方法) 代码: java.m ...
- MySQL查询缓存详解(总结)
MySQL查询缓存详解(总结) 一.总结 一句话总结: mysql查询缓存还是可以用用试一试,但是更推荐分布式,比如redis/memcache之流,将数据库中查询的数据和查询语句以键值对的方式存进分 ...
- php中class类文件引入方法汇总
在项目中 总是会用到类文件引入的操作,在此简单总结下: 方法一: 使用 include,require,include_once,require_once. 其中:*_once once意为曾经 ...
- webpack请求文件路径代理
在开发模式下,访问页面请求会跑到根路径,因为写的都 ./images 而index又在根目录, 所以访问地址会是 http://localhost:8080/images/abc.jpg 而实际 ...
- javaScript Queue
function Queue() { var items = []; this.enqueue = function(element) { items.push(element) } this.deq ...
- poj1285 Combinations, Once Again(泛化背包)
题目传送门 Combinations, Once Again Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1897 A ...
- sub
Popen.communicate(input=None)¶Interact with process: Send data to stdin. Read data from stdout and s ...