php框架kohana(二)

以下记录的是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不到数据的问题。

这样就可以完成“简单的登录跳转了”。

转载于:https://my.oschina.net/zlLeaf/blog/276117

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值