代码点火器错误“地址不被理解”

Posted

技术标签:

【中文标题】代码点火器错误“地址不被理解”【英文标题】:Code Iginiter Error 'The address wasn't understood' 【发布时间】:2016-08-14 02:03:24 【问题描述】:

我的新手代码点火器 3 带有 mysql 数据库和 xampp v3.2。

单击登录按钮时出现错误“地址不被理解”。 帮帮我……

这个配置

<code>`enter code here`
$config['base_url'] = 'localhost:8087/hris/';
$config['index_page'] = 'login.php';
</code>

还有我的 route.php

<code>
$route['default_controller'] = 'user_authentication';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
</code>

如何解决这个错误......

user_authentication.php

Class User_Authentication extends CI_Controller 

     //session_start(); //we need to start session in order to access it      through CI
   public function __construct() 
   
      parent::__construct();
      // Load form helper library
     $this->load->helper('form');
    // Load form validation library
    $this->load->library('form_validation');
    // Load session library
    $this->load->library('session');
    // Load database
    $this->load->model('login_database');
  
  // Show login page

 public function index() 
 
    $this->load->view('login');
 
// Show registration page

public function user_registration_show() 

  $this->load->view('registration_form');

// Validate and store registration data in database

public function new_user_registration() 

   // Check validation for user input in SignUp form
   $this->form_validation->set_rules('username', 'Username','trim|required|xss_clean');
   $this->form_validation->set_rules('email_value', 'Email', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

if ($this->form_validation->run() == FALSE) 

   $this->load->view('registration_form');
 else 
  
    $data = array(
           'user_name' => $this->input->post('UserID'),
           'user_email' => $this->input->post('email_value'),
           'user_password' => $this->input->post('password')
    );
   $result = $this->login_database->registration_insert($data);

if ($result == TRUE) 

   $data['message_display'] = 'Registration Successfully !';
   $this->load->view('login_form', $data);
 else 
   $data['message_display'] = 'Username already exist!';
   $this->load->view('registration_form', $data);



// Check for user login process

public function user_login_process() 

     $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');

if ($this->form_validation->run() == FALSE) 

   if(isset($this->session->userdata['logged_in']))
   
      $this->load->view('admin_page');
   else
      $this->load->view('login_form');
  
 else 
   $data = array(
           'username' => $this->input->post('username'),
            'password' => $this->input->post('password')
     );
  $result = $this->login_database->login($data);

if ($result == TRUE) 

    $username = $this->input->post('username');
   $result = $this->login_database->read_user_information($username);
   if ($result != false) 
   
       $session_data = array(
                       'username' => $result[0]->user_name,
                       'email' => $result[0]->user_email,
           );
// Add user data in session
    $this->session->set_userdata('logged_in', $session_data);
    $this->load->view('admin_page');

 else 
      $data = array(
   'error_message' => 'Invalid Username or Password'
   );
   $this->load->view('login_form', $data);



// Logout from admin page
public function logout() 

  // Removing session data
    $sess_array = array(
                    'username' => ''
        );
     $this->session->unset_userdata('logged_in', $sess_array);
     $data['message_display'] = 'Successfully Logout';
     $this->load->view('login_form', $data);


?>



this models login_database.php


Class Login_Database extends CI_Model 

       // Insert registration data in database
    public function registration_insert($data) 
    
        // Query to check whether username already exist or not
        $condition = "user_name =" . "'" . $data['user_name'] . "'";
        $this->db->select('*');
        $this->db->from('user_login');
        $this->db->where($condition);
        $this->db->limit(1);
        $query = $this->db->get();

        if ($query->num_rows() == 0) 
        

            // Query to insert data in database
              $this->db->insert('user_login', $data);
             if ($this->db->affected_rows() > 0) 
             
                return true;
             
         else 
          return false;



// Read data using username and password
public function login($data) 


    $condition = "user_name =" . "'" . $data['username'] . "' AND " . "user_password =" . "'" . $data['password'] . "'";
    $this->db->select('*');
    $this->db->from('user_login');
    $this->db->where($condition);
    $this->db->limit(1);
    $query = $this->db->get();

    if ($query->num_rows() == 1) 
      return true;
     else 
       return false;
  
 

// Read data from database to show data in admin page
public function read_user_information($username) 

$condition = "user_name =" . "'" . $username . "'";
$this->db->select('*');
$this->db->from('user_login');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();

 if ($query->num_rows() == 1) 
return $query->result();
 else 
return false;





this view ( login.php )

$this->load->helper('form'); 
if (isset($this->session->userdata['logged_in'])) 
header("location: http://localhost/login/index.php/user_authentication/user_login_process");
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Global stylesheets -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900" rel="stylesheet" type="text/css">
    <link href="assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/core.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/components.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/minified/colors.min.css" rel="stylesheet" type="text/css">
    <!-- /global stylesheets -->

    <!-- Core JS files -->
    <script type="text/javascript" src="assets/js/plugins/loaders/pace.min.js"></script>
    <script type="text/javascript" src="assets/js/core/libraries/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/core/libraries/bootstrap.min.js"></script>
    <script type="text/javascript" src="assets/js/plugins/loaders/blockui.min.js"></script>
    <!-- /core JS files -->

    <!-- Theme JS files -->
    <script type="text/javascript" src="assets/js/plugins/forms/styling/uniform.min.js"></script>

    <script type="text/javascript" src="assets/js/core/app.js"></script>
    <script type="text/javascript" src="assets/js/pages/login.js"></script>
    <!-- /theme JS files -->
</head>
<body>
    <!-- Main navbar -->
    <div class="navbar navbar-inverse">
        <div class="navbar-header">
            <a class="navbar-brand" href="index.html"><img src="assets/images/logo_light.png" ></a>

            <ul class="nav navbar-nav pull-right visible-xs-block">
                <li><a data-toggle="collapse" data-target="#navbar-mobile"><i class="icon-tree5"></i></a></li>
            </ul>
        </div>


    </div>
    <!-- /main navbar -->


    <!-- Page container -->
    <div class="page-container login-container">

        <!-- Page content -->
        <div class="page-content">

            <!-- Main content -->
            <div class="content-wrapper">

                <!-- Content area -->
                <div class="content">
                <?php
                echo form_open('user_authentication/user_login_process'); 
                ?>
                    <!-- Advanced login -->
                    <form action="" method="post">
                        <div class="panel panel-body login-form">
                            <div class="text-center">
                                <div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
                                <h5 class="content-group">Login to your account <small class="display-block">Your credentials</small></h5>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control" placeholder="Username" name="userid" id="userid" required> 
                                <div class="form-control-feedback">
                                    <i class="icon-user text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group has-feedback has-feedback-left">
                                <input type="text" class="form-control" placeholder="Password" name="pass" id="pass" required>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>

                            <div class="form-group login-options">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label class="checkbox-inline">
                                            <input type="checkbox" class="styled" checked="checked">
                                            Remember
                                        </label>
                                    </div>

                                    <div class="col-sm-6 text-right">
                                        <a href="login_password_recover.html">Forgot password?</a>
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <button type="submit" class="btn bg-blue btn-block">Login <i class="icon-arrow-right14 position-right"></i></button>
                            </div>

                        <?php echo form_close(); ?>

                            <div class="content-divider text-muted form-group"><span>Don't have an account?</span></div>
                            <a href="login_registration.html" class="btn btn-default btn-block content-group">Sign up</a>
                        </div>
                    </form>
                    <!-- /advanced login -->
                </div>
                <!-- /content area -->
            </div>
            <!-- /main content -->
        </div>
        <!-- /page content -->
    </div>
    <!-- /page container -->
</body>
</html>

</pre></code>

【问题讨论】:

你从哪里得到错误? 根目录下有login.php 文件吗? 【参考方案1】:

例如,对于在单击链接时遇到地址不被理解问题的任何人,只需确保将 http:// 添加到 $config['base_url'] 值,如果是上面的问题,你应该替换:

$config['base_url'] = 'localhost:8087/hris/';

通过

$config['base_url'] = 'http://localhost:8087/hris/';

希望有帮助:)

【讨论】:

【参考方案2】:

尝试将打开的表单更改为此

<?php
  echo form_open(base_url('User_Authentication/user_login_process')); 

  ?>

【讨论】:

我不认为这是解决方案 @naseeba c = stil error "http://[::1]/hris/user_authentication/user_login_process" - HTTP 错误 404。未找到请求的资源。 ??? 试试User_Authentication/user_login_process$config['index_page'] = ''; 把这个user_authentication改成User_Authentication 删除这个&lt;form action="" method="post"&gt;

以上是关于代码点火器错误“地址不被理解”的主要内容,如果未能解决你的问题,请参考以下文章

致命错误:调用非对象代码点火器 $query->num_rows()==1) 上的成员函数 where() [重复]

使用过滤器时数据表代码点火器不起作用

代码点火器:在非对象上调用成员函数 num_rows()

404 index() 函数代码点火器

您没有选择要上传的文件。 PHP 代码点火器

您请求的操作是不允许的。代码点火器