从旧版本的codeigniter 2迁移到codeigniter 3.1.2

I have an application running on codeigniter version 2 and want to move it to codeigniter 3.1.2(latest version). I have downloaded codeigniter 3.1.2 and to begin with i have rewritten the controller, model and view files. But i am getting a error saying ,

An Error Was Encountered
Unable to load the requested class: Database

My controller is Login.php

<?php
class Login extends CI_Controller
{
    var $data;

    function  __construct() {
        parent::__construct();
        $this->load->helper('cookie');  

        $is_admin_logged_in = $this->admin_init_elements->admin_logged_in_status();  
        global $USER;
        if($is_admin_logged_in == TRUE){
            redirect('home');
            //;
        }

        //populate viewfor header / footer elements

        $this->admin_init_elements->init_elements('N');
        $this->load->model('mod_login');

    }

    function index(){
        //if Admin already logged in, send to Admin home

        $this->data['message']='';
        $this->data['msg_class'] = '';
        $post_array=$this->input->post();

        $data['old_images']=$this->mod_common->getBgImages();

        if($this->input->cookie('remember') == 'on')
        {
            //echo $this->input->cookie('username');
            $this->data['message']=strip_tags($this->mod_login->check_cookie_login());
            if($this->data['message']=='Login Successful'){
                $this->data['msg_class'] = 'sukses';
                 redirect('home');              
            }else{
                $this->data['msg_class'] = 'gagal';
            }
        } 
        if($this->input->post('action')=='adminLogin'){

        //print_r($this->input->post()); die;

            if(isset($post_array['remember'])){
                $username_cookie= array(
                    'name'   => 'uusername',
                    'value'  => $post_array['username'],
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $password_cookie= array(
                    'name'   => 'userpass',
                    'value'  => $post_array['userpass'],
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $remember_cookie= array(
                    'name'   => 'remember',
                    'value'  => 'on',
                    'expire' => '865000',
                    'secure' => FALSE
                );

                $this->input->set_cookie($username_cookie); 
                $this->input->set_cookie($password_cookie); 
                $this->input->set_cookie($remember_cookie); 
                //die;

            }
            else
            {
                if($this->input->cookie('remember') == 'on')
                {
                    if($this->input->cookie('uusername') != $post_array['username'])
                    {
                        delete_cookie("remember");
                        delete_cookie("uusername");
                        delete_cookie("userpass");
                    }
                } 
            }

            $this->data['message']=strip_tags($this->mod_login->validate_admin_login());
            if($this->data['message']=='Login Successful'){
                $this->data['msg_class'] = 'sukses';
                 redirect('home');              
            }else{
                $this->data['msg_class'] = 'gagal';
            }
        } /*else if(isset()){

        }*/


    ///////////////////////
        $this->data['cookieRemember'] = $this->input->cookie('remember');
        $this->data['cookieUsername'] = $this->input->cookie('username');
        $this->data['cookiePassword'] = $this->input->cookie('userpass');
        //echo $this->data['cookieRemember'];echo $this->data['cookieUsername']; echo $this->data['cookiePassword'];
    //////////////////////

        $this->data['cookiename']  = $this->input->cookie('name', false);
        $this->data['cookieimage'] = $this->input->cookie('image', false);

        $sess_msg = $this->session->userdata('session_msg');
        $session_msg_class = $this->session->userdata('session_msg_class');
        if(isset($sess_msg) && $sess_msg!= ''){
            $this->data['message']=$sess_msg;
            $this->data['msg_class'] = $session_msg_class!=''?$session_msg_class:'gagal';
        }
        //render full layout, specific to this function
        $this->load->view('login', $this->data);
    }

////////////////////////////////////////////////////////////////////////////////    
    function forgot_password(){
         $this->load->view('send_reset_link', $this->data);
    }

    function send_pass_reset_link(){

        $post_array=$this->input->post();
        if($post_array['email']!='') { 
        $email_id=$post_array['email'];

        $user_id=$this->mod_common->get_userid($post_array['email']);

        foreach($user_id as $key){
            $id=$key['id'];
        }

        if($id>0){

        $link=base_url().'login/reset_password/'.$id;
        $message_body="<table>
                        <tr><td style='padding:10px 0px'>Dear User,</td></tr>
                        <tr><td style='padding:10px 0px'>You have received this communication in response to your request to reset your online portal account password. Please find below the link to reset your password</td></tr>
                        <tr ><td style='padding:10px 0px'><a href='".$link."' style='background:red;padding:5px 10px;color:#fff'> Reset Password </a></td></tr>
                        <tr ><td style='padding:10px 0px'>Regards,<br>Unfold</td></tr>

                       </table>";

        /*-------------------------*/
        //sending pass reset mail 
        $this->load->library('email');
/*      $config['protocol']     =   'sendmail';
        $config['mailpath']     =   '/usr/sbin/sendmail';
        $config['charset']      =   'iso-8859-1';
        $config['wordwrap']     =    TRUE;
        $config['mailtype']     =   'html';  */

        $config['protocol']     = 'sendmail';
        $config['mailpath']     = '/usr/sbin/sendmail';
        $config['charset']      = 'iso-8859-1';
        $config['wordwrap']     = TRUE;
        $config['mailtype']     = 'html'; 
        $this->email->initialize($config);

        $this->email->set_newline("
");
        $this->email->from("info@unfold.com","Admin");//email id and name of the sender
        $this->email->to($email_id); // email id of the recipient
        $this->email->subject("Reset Password"); //The subject line
        $this->email->message($message_body);
        $this->email->send();
        //$this->email->clear();
        //show_error($this->email->print_debugger());
        //die;
        /*-------------------------*/
        $this->data['reset_link_msg']="An email with the password reset link has been sent to your mail address.";
     }else{
        $this->data['reset_link_msg']="Sorry! The email entered is not in our database.";
     }  
        } else {$this->data['reset_link_msg'] = '';}

        $this->load->view('send_reset_link', $this->data);

    } 

    function reset_password(){
        if($this->input->post()){   

            $post_array=$this->input->post();
            $this->data['reset_msg']=$this->mod_common->reset_password($post_array);
            $this->load->view('reset_password', $this->data);
        }

        if($this->uri->segment(3)!=''){
         $this->data['id']=$this->uri->segment(3);
         $this->load->view('reset_password', $this->data);
        }
        else{
            redirect('login');
        }
    }










    // Admin authentication ----------
}

?>

My Model is Mod_login.php

<?php 
    class Mod_login extends CI_Model{
        var $myTables;
        #print_r($this->db->last_query());

        function  __construct(){
            parent::__construct();
            $this->myTables=$this->config->item('myTables');
            $this->load->helper('cookie');   
        }

        function validate_admin_login(){
            $this->form_validation->set_rules('username', 'Username', 'trim|required');
            $this->form_validation->set_rules('userpass', 'Password', 'trim|required');
            if ($this->form_validation->run() == TRUE){
                return $this->check_admin_login();
            }else{
                return validation_errors();
            }

        }
        function check_cookie_login(){

            $this->db->where('username', trim($this->input->cookie('uusername')));
            $this->db->where('userpass ', sha1(trim($this->input->cookie('userpass'))));
            $this->db->where('status', '1');
            $this->db->where('deleted', '0');
            $this->db->select('*');
            $query = $this->db->get($this->myTables['users']);

            if($query->num_rows() > 0){
                $row = $query->row();
                $this->db->where('userid', $row->id);
                $this->db->select('firstname,lastname,profileimage');
                $query1 = $this->db->get($this->myTables['users_details']);
                $row1 = $query1->row();
                $newdata = array(
                                    'is_admin_logged_in' => true,
                                    'admin_user_name' => $row->username,
                                    'admin_userpass' => $row->userpass,
                                    'admin_id'=>$row->id,
                                    'admin_lastlogin'=>date("d-m-Y H:i:s",$row->lastlogin),
                                    'admin_lastloginip'=>$row->lastloginip,
                                    'lastrefresh'=>time() 
                            );

                $this->session->set_userdata($newdata); 
                $this->update_admin_login_time($this->session->userdata('admin_id'));
                $this->admin_init_elements->set_global_user($row->username,$row->userpass);
                if($this->input->post('remember'))
                {
                    $cookie = array('name'   => 'username','value'  => $row->username,'expire' =>  time()+7600,'secure' => false);
                    $this->input->set_cookie($cookie);
                }
                $name = $row1->firstname.' '.$row1->lastname;
                $cookie1 = array('name'   => 'name','value'  => $name,'expire' =>  time()+7600,'secure' => false);
                $this->input->set_cookie($cookie1); 
                $cookie2 = array('name'   => 'image','value'  => $row1->profileimage,'expire' =>  time()+7600,'secure' => false);
                $this->input->set_cookie($cookie2); 


                return 'Login Successful';
            }else{

            }

        }
        function check_admin_login(){

            $this->db->where('username', trim($this->input->post('username')));
            $this->db->where('userpass ', sha1(trim($this->input->post('userpass'))));
            $this->db->where('status', '1');
            $this->db->where('deleted', '0');
            $this->db->select('*');
            $query = $this->db->get($this->myTables['users']);
            if($query->num_rows() > 0){
                $row = $query->row();
                $this->db->where('userid', $row->id);
                $this->db->select('firstname,lastname,profileimage');
                $query1 = $this->db->get($this->myTables['users_details']);
                $row1 = $query1->row();
                $newdata = array(
                                    'is_admin_logged_in' => true,
                                    'admin_user_name' => $row->username,
                                    'admin_userpass' => $row->userpass,
                                    'admin_id'=>$row->id,
                                    'admin_lastlogin'=>date("d-m-Y H:i:s",$row->lastlogin),
                                    'admin_lastloginip'=>$row->lastloginip,
                                    'lastrefresh'=>time() 
                            );

                $this->session->set_userdata($newdata); 
                $this->update_admin_login_time($this->session->userdata('admin_id'));
                $this->admin_init_elements->set_global_user($row->username,$row->userpass);
                if($this->input->post('remember'))
                {
                    $cookie = array('name'   => 'username','value'  => $row->username,'expire' =>  time()+7600,'secure' => false);
                    $this->input->set_cookie($cookie);
                }
                $name = $row1->firstname.' '.$row1->lastname;
                $cookie1 = array('name'   => 'name','value'  => $name,'expire' =>  time()+7600,'secure' => false);
                $this->input->set_cookie($cookie1); 
                $cookie2 = array('name'   => 'image','value'  => $row1->profileimage,'expire' =>  time()+7600,'secure' => false);
                $this->input->set_cookie($cookie2); 


                return 'Login Successful';
            }else{
                return 'Incorrect Username or Password.';
            }

        }
        function logout()
        {
            global $USER;

            $query1 = $this->db->query("Select * from pr_system_attendance where userid = '".$USER->id."' and DATE(`login_time`) = CURDATE()");
            date_default_timezone_set('Asia/Calcutta');
            if($query1->num_rows() > 0)
            {
                $row = $query1->row();

                $sql1 = "UPDATE pr_system_attendance set logout_time = '".date('Y-m-d H:i:s')."'  where userid = '".$USER->id."' and DATE(`login_time`) = CURDATE()";



                $query2 = $this->db->query($sql1);


            }
            $sql="UPDATE `".$this->myTables['users']."` SET 
                    `if_online` = '0'
                     WHERE `id` = '".$USER->id."'" ;
            $query=$this->db->query($sql);  

        }
        function update_admin_login_time($id){
            $sql="UPDATE `".$this->myTables['users']."` SET 
                    `lastlogin` = '".time()."',
                    `if_online` = '1',
                    `lastrefresh` = '".time()."',
                    `lastloginip` = '".$_SERVER['REMOTE_ADDR']."'
                    WHERE `id` = '".$id."'" ;
            $query=$this->db->query($sql);  
            $query1 = $this->db->query("Select * from pr_system_attendance where userid = '".$id."' and DATE(`login_time`) = CURDATE()");
            if($query1->num_rows() <= 0)
            {
                $sql1 = "INSERT INTO pr_system_attendance(userid,login_time,login_ip) VALUES('".$id."','".date('Y-m-d H:i:s')."','".$_SERVER['REMOTE_ADDR']."')";
                $query2 = $this->db->query($sql1);
            }

        }

    }

My view file is login.php

<?php global $SITE; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php error_reporting(0); ?>
        <!-- Bootstrap 3.3.5 -->
        <link rel="stylesheet" href="<?php echo base_url(); ?>assets/bootstrap/css/bootstrap.min.css">
        <!-- Font Awesome -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
        <!-- Ionicons -->
        <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
        <!-- Theme style -->
        <link rel="stylesheet" href="<?php echo base_url(); ?>assets/dist/css/main.css">
        <!-- iCheck -->
        <link rel="stylesheet" href="<?php echo base_url(); ?>assets/plugins/iCheck/square/blue.css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
            <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <?php 
    $old_home_bg = $old_images[0]['login_bg'];
$home_url = base_url().'assets/images/1406147562_1213214397.jpg';
    ?>
<body class="hold-transition login-page">
    <div class="login-box">
      <div class="col-md-6 hide-side" >
        <img src="<?php echo base_url(); ?>/assets/images/side_login.jpg">
      </div>
       <div class="col-md-6">
      <div class="login-logo">
        <a href=""><img src="<?php echo base_url(); ?>assets/images/logo.png" class="logo_login" alt="" width="190px"/> </a>
      </div>
      <div class="login-box-body">

       <?php echo form_open('login/', array('method'=>'post','name'=>'adminLoginForm','id'=>'adminLoginForm','class'=>'form-vertical login-form'));?>
        <?php if($message!='') {?>
        <div class="messages">

            <div class="has-error">
            <?php echo $message; ?>
            </div>
        </div>
        <?php } ?>
          <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-user"></i></span>
                <input type="text" class="form-control login" id="username" name="username" placeholder="Username">
            </div>

          </div>
          <div class="form-group has-feedback">
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                <input type="password" class="form-control" id="userpass" name="userpass" placeholder="Password">
            </div>
          </div>
          <?php
                                    echo form_hidden('action','adminLogin');
         ?>
          <div class="row">
            <div class="col-xs-8">
             <div style="float:left;margin-top: 7px;">
                                    <input type="checkbox" name="remember" /> Remember <br>
                                    <?php 
                                        echo anchor(site_url("login/forgot_password"),'<div style="text-align:right;margin-top:5px;color:#C95356;font-weight:bold;">Forgot Password</div>','title="Need help?"');        
                                        echo '&nbsp; &nbsp;'; 
                                        //echo anchor(site_url("signup"),$this->lang->line('label_sign_up')); 
                                    ?>
                                </div>
            </div><!-- /.col -->
            <div class="col-xs-4">
              <button type="submit" name="login" class="btn btn-primary btn-block btn-flat btn-login">Sign In</button>
            </div><!-- /.col -->
          </div>
        </form>
        </div><!-- /.login-box-body -->
        </div>
        <div class="clearfix"></div>
    </div><!-- /.login-box -->
    <div class="login_footer">
        <div class="fl" style="float:left;padding:0px 20px;color:#fff;">
            &copy; 2015 Zipbizz <br>
            <a href="" style="color:#fff;">Terms & Conditions</a>
        </div>
        <div class="fr" style="float:right; padding:0px 20px;color:#fff;">
            Powered By<br>
            <img src="<?php echo base_url(); ?>/assets/images/footer_logo.png">
        </div>
    </div>
    <!-- jQuery 2.1.4 -->
    <script src="<?php echo base_url(); ?>assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>
    <!-- iCheck -->
    <script src="<?php echo base_url(); ?>assets/plugins/iCheck/icheck.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>
    <script>
      $(function () {
        $('input').iCheck({
          checkboxClass: 'icheckbox_square-blue',
          radioClass: 'iradio_square-blue',
          increaseArea: '20%' // optional
        });
        $.backstretch([
            "<?php echo $home_url; ?>"
            ], {
              fade: 1000,
              duration: 8000
        }); 
      });
    </script>

</body>
</html>

1个回答



您是否尝试在application / config / autoload.php上自动加载数据库</ p>

  $ autoload ['libraries'] = array('database'); 
</ code> </ pre>

确保在application / config / database.php中设置了数据库连接< / p>
</ div>

展开原文

原文

Have you tried to autoload the database on application/config/autoload.php

$autoload['libraries'] = array('database');

Make sure you have set your database connection in application/config/database.php

duangu4943
duangu4943 按照此处标记的所有步骤进行了codeigniter.com/userguide3/installation/upgrade_223.html并且它工作了..也是上面改了,谢谢
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问