标签:
<?php
I18n::lang(‘en-us‘);
HTTP::$protocol
Kohana::$environment
Kohana::init(array(
‘base_url‘ => ‘/‘,
‘index_file‘=>‘index.php‘,
‘charset‘=>‘utf-8‘,
‘errors‘=> TRUE , //开启错误处理
‘profile‘=> TRUE , //剖析 生产模式时候要记得开启
‘lifetime‘=>60, //设置缓存文件多久一次更新
‘caching‘=> TRUE, ///开启文件缓存
// ‘cache_dir‘=>"cache", //缓存存放路径
‘expose‘=> TRUE //头信息 X-Powered-By header
));
Kohana::$log->attach(new Log_File(APPPATH.‘logs‘));
Kohana::$config->attach(new Config_File);
Kohana::modules(array(
‘auth‘ => MODPATH.‘auth‘, // Basic authentication
‘cache‘ => MODPATH.‘cache‘, // Caching with multiple backends
// ‘codebench‘ => MODPATH.‘codebench‘, // Benchmarking tool
‘database‘ => MODPATH.‘database‘, // Database access
‘image‘ => MODPATH.‘image‘, // Image manipulation
‘minion‘ => MODPATH.‘minion‘, // CLI Tasks
// ‘orm‘ => MODPATH.‘orm‘, // Object Relationship Mapping
// ‘unittest‘ => MODPATH.‘unittest‘, // Unit testing
‘userguide‘ => MODPATH.‘userguide‘, // User guide and API documentation
‘pagination‘ => MODPATH.‘pagination‘, //分页
‘captcha‘ => MODPATH.‘captcha‘, //验证码
));
Route::set(‘default‘, ‘(<controller>(/<action>(/<id>)))‘)
->defaults(array(
‘controller‘ => ‘welcome‘,
‘action‘ => ‘index‘,
));
Cookie::$salt = ‘put-your-salt-here‘;
Request对象中有
Request::$user_agent /浏览器类型
Request::$client_ip
$this->_uri = "welcome"
$this->_header = new HTTP_Header(array());
$this->_routes = $injected_routes; 空 arrray
$this->_route //Kohana_Route 路由对象
$this->_protocol =“http1.1”
$this->_get
$this->_post
$this->_method
$this->referrer
$this->body
$this->requested_with 是否ajax
$this->cookie
$this->_external // 这是外部路线吗? 返回false
$this->_directory
$this->_controller
$this->_action
$this->_params
$this->_client = new Request_Client_Internal(array()) 继承 Kohana_Request_Client_External 继承 Request_Client 继承 Kohana_Request_Client
前提Response 继承 Kohana_Response 实现接口 HTTP_Response 继承 Kohana_HTTP_Response 继承 HTTP_Message 继承 Kohana_HTTP_Message 继承 Kohana_HTTP_Message
request->execute(){最后$this->_client->Kohana_Request_Client::execute()-> Response::factory(array(‘_protocol‘ => http/1.1)
现在走到 Kohana_Request_Client::execute()
Kohana_Request_Client_External:: execute_request(){方法}
而Response 有如下属性
$this->_header = new HTTP_Header;
$this->_protocol => 1.1
如何重定向用户请求
[返回目彔]
如果你想重定向用户请求道一个新癿页面戒者新癿路由。你可以使用
用法
HTTP::redirect(‘admin/index/login‘);
Request::instance()->redirect( Route::get(‘demo-sample‘)->uri(array(‘category‘=>‘books‘,
‘id‘=>5)));
设置你的Cookie的属性
Cookies使用几个属性用来帮助你决定数据如何加密以及什么网站或域名可以访问它。这些属性设置为Cookies类的静态属性
// 设置魔法 salt到 cookie
Cookie::$salt = ‘kookykookie‘;
// 设置cookie 多久过期
Cookie::$expiration = 43200;
// 限制有效的cookie路径
Cookie::$path = ‘/‘;
// 限制可以访问cookie的域名
Cookie::$domain = ‘www.kerkness.ca‘;
// 只可以用安全连接传输cookie
Cookie::$secure = TRUE;
// 只可以用HTTP传输cookie,不能用Javascript传输。
Cookie::$httponly = TRUE;
建立控制器
建立我们的第一个控制器。记住以下预定
控制器文件名应该小写,如
album.php
控制器类必须映射文件名而且首字母大写,还要添加_Controller.
如:
Album_Controller
必须从父类继承
class Album_Controller extends Controller
{
public function __construct()
{
parent::__construct();
$this->album_model = new Album_Model;
$this->genre_model = new Genre_Model;
$this->list_view = new View(‘list‘);
$this->update_view = new View(‘update‘);
$this->create_view = new View(‘create‘);
}
public function index()
{
echo "My first controller";
}
}
///////////数据库配置那里
execute(‘可以指定使用哪个数据库配置‘,‘指定使用pdo‘) //默认是default
execute(‘alternate‘,‘pdo‘);
//查询一 返回结果对象
$result=DB::select(‘name‘)->from(‘a‘)->execute(‘default‘,‘mysql‘);
//查询二 返回数组
$result=DB::select(‘name‘)->from(‘a‘)->execute(‘alternate‘,‘pdo‘)->as_array();
//查询三 结果作为标准类对象返回
$result=DB::select(‘name‘)->from(‘a‘)->execute()->current();
//查询四 仅返第一行
$result=DB::select(‘name‘)->from(‘a‘)->execute()->current();
//查询五 列名的别名
$result=DB::select(array(‘name‘,‘name_bieming‘),array(‘money‘,‘m‘))->from(‘a‘)->execute()->current();
//查询六 where条件查询
$result=DB::select()->from(‘a‘)->where(‘name‘,‘=‘,‘lisi‘)->execute();
//更新
$total_rows=DB::update(‘a‘)->set(array(‘name‘,‘wangwu‘))->where(‘money‘,‘=‘,‘200‘)->execute();
//删除
//$total_rows=DB::delete(‘a‘)->where(‘money‘,‘=‘,‘200‘)->execute();
echo Kohana::debug($total_rows);
标签:
原文地址:http://www.cnblogs.com/sixiong/p/5757917.html