简体   繁体   English

登录后离子身份验证Codeigniter登录抛出错误

[英]Ion auth Codeigniter Login throwing errors after logging in

This is my first project using both Codeigniter and Ion Auth and I've finished this tutorial: http://www.rappasoft.com/tutorials/view/5#.U1bJLeZdWpo 这是我同时使用Codeigniter和Ion Auth的第一个项目,并且我已经完成了本教程: http : //www.rappasoft.com/tutorials/view/5#.U1bJLeZdWpo

But now that I've reached the end, I have an error that is appearing when all of my code looks identical to the tutorial. 但是现在我已经结束了,当我所有的代码看起来都与教程相同时,我会出现一个错误。 The error is: 错误是:

Message: Creating default object from empty value 消息:从空值创建默认对象

Filename: core/MY_Controller.php 文件名:core / MY_Controller.php

Line Number: 13 行号:13

But the odd thing is that the code from the MY_Controller file is copied right from the tutorial. 但是奇怪的是,MY_Controller文件中的代码是直接从教程中复制的。 Here's the code I have: 这是我的代码:

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');  

class MY_Controller extends CI_Controller {
    public function __construct() {
       parent::__construct();

       if (!$this->ion_auth->is_admin()) {
            redirect('auth/login');
       } else {
            //Store user in $data
            $data->user_info = $this->ion_auth->user()->row();
            //Load $the_user in all views
            $this->load->vars($data);        
       }
    }
}

?>

The correct view loads underneath the error but obviously I'd like to know what's wrong. 正确的视图会在错误下方加载,但显然我想知道出了什么问题。 Since this is my first turn time working with ion-auth and I'm relatively new to code igniter as well, I was wondering if anyone knew how to go about debugging an error like this. 由于这是我第一次使用ion-auth,并且对代码点火器也比较陌生,所以我想知道是否有人知道如何调试这样的错误。 Teach a man to fish, feed him for a lifetime! 教男人钓鱼,养活他一辈子! I'd really appreciate not just solutions but methods so I can learn and do this on my own! 我不仅要感谢解决方案,还要感谢方法,因此我可以自己学习和做! Thanks everyone! 感谢大家!

Are you working on PHP 5.4+ ? 您正在使用PHP 5.4+吗?

In that case, you must declare $data before using it: 在这种情况下,必须在使用$ data之前声明它:

Change: 更改:

$data->user_info = $this->ion_auth->user()->row();

to

$data = new stdClass(); 
$data->user_info = $this->ion_auth->user()->row();

and try again. 然后再试一次。 Hpe it helps! 希望它有帮助!

I think I might have figured it out. 我想我可能已经知道了。 I think the issue might be that the default login information (the ones provided by ion auth) do not have any additional information in the database. 我认为问题可能在于默认登录信息(由ion auth提供的登录信息)在数据库中没有任何其他信息。 This means that when the $data variable goes to set the additional account information, it doesn't find anything. 这意味着,当$ data变量用于设置其他帐户信息时,它什么也找不到。 It's not a strong enough error to crash the page but it is warning me that there is no other account information available even though it is supposed to be looking for more info. 这不是一个足以使页面崩溃的严重错误,但它警告我,即使应该查找更多信息,也没有其他帐户信息可用。

So how to fix this? 那么如何解决呢? Create a user for testing purposes with a full compliment of account information and see if that solves the problem. 创建一个具有完整帐户信息补充的用于测试目的的用户,然后查看是否可以解决问题。 The only problem is that I don't know how to add new users using ion auth and my views aren't sophisticated enough yet to make that process easy. 唯一的问题是,我不知道如何使用ion auth添加新用户,而我的视图还不够复杂,无法简化该过程。

I've looked at the create_user() method in the auth.php file but when you press submit after filling out the form, it kicks you back to the same page with all the info. 我已经看过auth.php文件中的create_user()方法,但是当您填写表单后按Submit时,它将把您带回到所有信息的同一页面。 I have a feeling an edit needs to be done here although I don't quite know what to change. 我感觉需要在这里进行编辑,尽管我不太知道要更改什么。 I've been looking on the ion auth documentation but it seems a bit... sparse. 我一直在寻找ion auth文档,但似乎有点...稀疏。 I think I'm on the right track although I'd really like to hear if someone else has a better explanation or solution. 尽管我真的很想听听其他人是否有更好的解释或解决方案,但我认为我的方向正确。 As of now, I haven't actually fixed it yet. 截至目前,我尚未真正修复它。 Just deduction. 只是扣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM