以下记录的是kohana的controller和view
一、在kohana/application/view新建index.php,代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
</head>
<body>
<form action="/user/user/login" method="post">
用户名:<input name="username" type="text">
密码:<input name="password" type="password">
<input type="submit" value="登录">
</form>
</body>
</html>
修改kohanademo/application/classes/controller/welcome.php如下
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller {
public function action_index()
{
$view = View::factory('index');
$this->response->body($view);
}
} // End Welcome
这样访问http://kohanademo.my.com就可以看到登陆界面了
二、在kohanademo/application/classes/controller下新建user文件夹,并且在user文件夹下新建user.php,内容如下
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_User_User extends Controller {
public function action_index()
{
$username = Session::instance()->get('username');
$this->response->body('logined:'.$username);
}
public function action_login()
{
if($this->request->post())
{
$username = $this->request->post('username');
$password = $this->request->post('password');
Session::instance()->set('username',$username);
$this->request->redirect('/user/user/index');
}
}
}
?>
三、修改nginx配置
修改如下
server
{
listen 80;
server_name kohanademo.my.com ;
#server_name localhost;
index index.html index.htm index.php;
root /mnt/hgfs/code/kohanademo;
location ~ ^(.*)svn\/ {
deny all;
}
location ~ \swp$ {
deny all;
}
location ~ /user/$
{
try_files $uri /index.php?$query_string;
location ~ .*\.php$
{
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
expires off;
}
}
location ~ .*\.php$
{
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
expires off;
}
access_log /data/logs/kohanademo.my.com.log access;
}
加上了user段,否则会出现post不到数据的问题。
这样就可以完成“简单的登录跳转了”。