用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4427|回复: 3
收起左侧

php的bug? kohana的bug? 还是我用错了?

[复制链接]
发表于 2008-6-20 16:59:44 | 显示全部楼层 |阅读模式
首先问一下: kohana读音是什么? 表示什么意思?
我从官方下载了2.1.1这个版本,奇怪的是form::input('idname','中文'),中的中文有时候被清空了,是有时候啊!!!!! 我跟踪了一下程序发现是html::specialchars这个函数的问题.
发现过程: 官方代码中有个auth module,我发现控制器auth中的可能是有些老代码不能用,我就改写了,用英文是没问题的,中文有时候就不见了.
我的环境: win xp sp2,apache 2.2.8,php 5.2.6,mysql 4.1.22. php指定default_charset=utf-8.
auth.php改写后如下:

PHP复制代码
 
class Auth_Controller extends Controller {
 
 
        public function __construct()
        {
                parent::__construct();
 
                // Load some libraries
                //foreach(array('profiler', 'auth', 'session') as $lib)
                //{
                //        $class = ucfirst($lib);
                //        $this->$lib = new $class();
                //}
        }
 
        function index()
        {
                // Display the install page
                echo new View('auth/install');
        }
 
        function create()
        {
                header('Content-type: text/html; charset=gb2312');
 
                if(! empty($_POST))//$this->input->post()
                {
                        $this->validation->set_rules(array
                        (
                                // Format:
                                // key          friendly name,  validation rules
                                'email' => array('电子邮件', '=trim|required[6,127]|valid_email_rfc'),
                                'username' => array('用户名', '=trim|required[4,32]'),
                                'password' => array('密码', '=trim|required[4,50]'),
                        ));
                       
                        if ($this->validation->run())
                        {
                                // Create new user
                                $user = new User_Model;
 
                                if ( ! $user->username_exists($this->input->post('username')))
                                {
                                        foreach($this->input->post() as $key => $val)
                                        {
                                                // Set user data
                                                $user->$key = $val;
                                        }
 
                                        if ($user->save() AND $user->add_role('login'))
                                        {
                                                // Redirect to the login page
                                                url::redirect('auth/login');
                                        }
                                }
                        }
                        else
                        {
                                $this->validation->error_format("<li>{message}</li>");
                         
                                ?>
                                <ul>
                                        <?php echo $this->validation->error_string ?>
                                </ul>
                                <?php
                        }
                }//有数据
               
                print form:pen('auth/create', array('id'=>'create_form'));
                print form::label('input_email', 'Email Address: ');
                print form::input('email', $this->input->post('email'));
                print form::label('input_name', 'User Name: ');
                print form::input('username', $this->input->post('username'));
                print form::label('input_password', 'Password: ');
                print form::password("password",$this->input->post('password'));
                print form::submit('submit', '提交');
                print form::close();
 
        }
 
        function login()
        {
                header('Content-type: text/html; charset=gb2312');
                if ( ! $this->session->get('user_id')) //没有登录
                {
                        if(! empty($_POST))
                        {
                                $this->validation->set_rules(array
                                (
                                        // Format:
                                        // key          friendly name,  validation rules
                                        'username' => array('用户名', '=trim|required[4,32]'),
                                        'password' => array('密码', '=trim|required[4,50]'),
                                ));
                                if ($this->validation->run())
                                {
                                        // Load the user
                                        $user = new User_Model($this->input->post('username'));
 
                                        // Attempt a login
                                        if ($this->auth->login($user, $this->input->post('password')))
                                        {
                                                echo "<h4>Login Success!</h4>";
                                                echo "<p>Your roles are:</p>";
                                                echo Kohana::debug($this->session->get('roles'));
                                        }
                                        else
                                        {
                                                echo "<h4>Login Failed!</h4>";
                                        }
                                        //return;
                                }
                                else
                                {
                                        $this->validation->error_format("{message}<br/>");
                                        echo $this->validation->error_string;
                                }
                        }//没有收到数据
 
                        print form:pen('auth/login', array('id'=>'login_form'));
                        print form::label('input_name', 'User Name: ');
                        print form::input('username', $this->input->post('username'));
                        print form::label('input_password', 'Password: ');
                        print form::password("password",$this->input->post('password'));
                        print form::submit('submit', '登录');
                        print form::close();
                }//没有登录
 
                if ($this->session->get('user_id'))
                {
                        print form:pen('auth/logout', array('id'=>'logout_form'));
                        print form::submit('submit', '注销');
                        print form::close();
                }
        }
 
        function logout()
        {
                // Load auth and log out
                $auth = new Auth();
                $auth->logout(TRUE);
 
                // Redirect back to the login page
                url::redirect('auth/login');
        }
 
} // End Auth_Controller
复制代码
 楼主| 发表于 2008-6-20 17:05:55 | 显示全部楼层
上面的header('Content-type: text/html; charset=gb2312');是一因为浏览器传送到浏览器的中文就是gb2312编码,浏览器用的是utf8解析,乱码,我只是测试一下,偷懒就加了这个.这个问题的出现,肯定和编码有关,我猜
 楼主| 发表于 2008-6-20 17:19:14 | 显示全部楼层
上面的"提交"能出来,登录,注销显示不出来
 楼主| 发表于 2008-6-22 15:49:30 | 显示全部楼层
php5.2.3正常 5.2.6的bug

本版积分规则