【问题标题】:Object Not found in xampp server in code igniter?在codeigniter的xampp服务器中找不到对象?
【发布时间】:2016-08-07 00:46:04
【问题描述】:

我是代码点火器的新手,我正在为此开发简单的登录系统,我正在使用 xampp,我在文件夹 code/ 中上传了代码点火器,以下是 mvc 中的代码

控制器登录.php

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

  class Login extends CI_Controller
     {

 public function __construct()
 {
      parent::__construct();
      $this->load->library('session');
      $this->load->helper('form');
      $this->load->helper('url');
      $this->load->helper('html');
      $this->load->database();
      $this->load->library('form_validation');
      //load the login model
      $this->load->model('login_model');
 }

 public function index()
 {
      //get the posted values
      $username = $this->input->post("txt_username");
      $password = $this->input->post("txt_password");

      //set validations
      $this->form_validation->set_rules("txt_username", "Username", "trim|required");
      $this->form_validation->set_rules("txt_password", "Password", "trim|required");

      if ($this->form_validation->run() == FALSE)
      {
           //validation fails
           $this->load->view('login_view');
      }
      else
      {
           //validation succeeds
           if ($this->input->post('btn_login') == "Login")
           {
                //check if username and password is correct
                $usr_result = $this->login_model->get_user($username, $password);
                if ($usr_result > 0) //active user record is present
                {
                     //set the session variables
                     $sessiondata = array(
                          'username' => $username,
                          'loginuser' => TRUE
                     );
                     $this->session->set_userdata($sessiondata);
                     redirect("index");
                }
                else
                {
                     $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Invalid username and password!</div>');
                     redirect('login/index');
                }
           }
           else
           {
                redirect('login/index');
           }
      }
 }
 }?>

模型是 login_model.php

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

 class login_model extends CI_Model
      {
   function __construct()
        {
      // Call the Model constructor
      parent::__construct();
         }

 //get the username & password from tbl_usrs
   function get_user($usr, $pwd)
    {
        $sql = "select * from tbl_usrs where username = '" . $usr . "' and password = '" . md5($pwd) . "' and status = 'active'";
      $query = $this->db->query($sql);
      return $query->num_rows();
 }
  }?>

View 是 login_view

   <!DOCTYPE html>
   <html>
     <head>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Login Form</title>
 <!--link the bootstrap css file-->
 <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

 <style type="text/css">
 .colbox {
      margin-left: 0px;
      margin-right: 0px;
 }
 </style>
   </head>
           <body>
              <div class="container">
                      <div class="row">
                 <div class="col-lg-6 col-sm-6">
           <h1>COLORS</h1>
      </div>
      <div class="col-lg-6 col-sm-6">

           <ul class="nav nav-pills pull-right" style="margin-top:20px">
                <li class="active"><a href="#">Login</a></li>
                <li><a href="#">Signup</a></li>
           </ul>

           </div>
          </div>
       </div>
        <hr/>

              <div class="container">
               <div class="row">
      <div class="col-lg-4 col-sm-4 well">
      <?php 
      $attributes = array("class" => "form-horizontal", "id" => "loginform", "name" => "loginform");
      echo form_open("login/index", $attributes);?>
      <fieldset>
           <legend>Login</legend>
           <div class="form-group">
           <div class="row colbox">
           <div class="col-lg-4 col-sm-4">
                <label for="txt_username" class="control-label">Username</label>
           </div>
           <div class="col-lg-8 col-sm-8">
                <input class="form-control" id="txt_username" name="txt_username" placeholder="Username" type="text" value="<?php echo set_value('txt_username'); ?>" />
                <span class="text-danger"><?php echo form_error('txt_username'); ?></span>
           </div>
           </div>
           </div>

           <div class="form-group">
           <div class="row colbox">
           <div class="col-lg-4 col-sm-4">
           <label for="txt_password" class="control-label">Password</label>
           </div>
           <div class="col-lg-8 col-sm-8">
                <input class="form-control" id="txt_password" name="txt_password" placeholder="Password" type="password" value="<?php echo set_value('txt_password'); ?>" />
                <span class="text-danger"><?php echo form_error('txt_password'); ?></span>
           </div>
           </div>
           </div>

           <div class="form-group">
           <div class="col-lg-12 col-sm-12 text-center">
                <input id="btn_login" name="btn_login" type="submit" class="btn btn-default" value="Login" />
                <input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-default" value="Cancel" />
           </div>
           </div>
      </fieldset>
      <?php echo form_close(); ?>
      <?php echo $this->session->flashdata('msg'); ?>
               </div>
             </div>
             </div>

          <!--load jQuery library-->
       <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
       <!--load bootstrap.js-->
     <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
     </body>
      </html>

我使用的IN配置 $config['index_page'] = ''; 在我使用的路线中 $route['default_controller'] = '登录'; $route['404_override'] = ''; $route['translate_uri_dashes'] = 假; 在访问 localhost/code/ 时它工作正常,但是当单击登录按钮时,它将转到 url http://localhost/code/localhost/login/index 并显示找不到对象 ERROR 404

【问题讨论】:

  • 在配置文件中设置你的 base_url
  • 我将基本 url 设置为 localhost
  • 同时添加您的项目名称
  • 我添加了 localhost/code 但它显示 localhost/code/localhost/code/login/index object not found 和错误 404
  • 如果您使用 CI3 版本,根据用户指南,您的文件和类名的首字母应为大写。

标签: php codeigniter


【解决方案1】:

打开application/config/config.php 并设置您的base_url()。例如:$config['base_url'] = 'http://localhost/code/';

/code文件夹(应用程序和系统文件夹所在的位置)下创建.htaccess文件,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

【讨论】:

  • 它正在工作,但在我输入登录详细信息后 [link] localhost/code/login/index 显示 404 错误
  • 您必须在您的 routes.php 文件中添加所有页面(包括您的 POST URL)。它会修复这个错误。
  • 打开 application/config/routes.php 并添加如下行:$route['some_url'] = 'Controller_name/function_name'; 为您自己的系统编辑此示例。
【解决方案2】:

在\code\中创建.htaccess文件

作为

RewriteEngine On
RewriteBase /code/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

在 config/config.php 中

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

希望对你有帮助。

【讨论】:

    【解决方案3】:

    我得到了如下所示的相同错误。我正在使用 php/codeigniter。我在我的配置文件中定义了$config['base_url'] = 'http://localhost/******';。仍然显示相同的问题。

    找不到对象!在此服务器上找不到请求的 URL。如果 您手动输入了 URL,请检查您的拼写并重试。 如果您认为这是服务器错误,请联系站长。

    我该如何解决这个问题。

    第 1 步:首先我检查了 httpd.conf 文件。 mod_rewrite 被导入了。

    第2步:检查的文件是否位于实际位置。

    第 3 步:检查重定向或锚标记中的拼写错误。

    第 4 步:检查 application/config.php 文件中的 $config['base_url'] 变量。

    第 5 步:检查 application/config.ph 文件中的 $config['index_page'] 变量。这是我的实际问题。我将其设置为空白,我的 mod_rewrite 模块有问题。当我输入$config['index_page']='index.php' 时,它开始为我工作。

    【讨论】:

      猜你喜欢
      • 2018-04-19
      • 2013-09-05
      • 2015-03-18
      • 2017-09-29
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      相关资源
      最近更新 更多