简体   繁体   English

php echo base_url()带我到404

[英]php echo base_url() bringing me to 404

I am following this tutorial to make a form to insert data to my database. 我正在按照本教程制作将数据插入到数据库的表单。 I have come to a problem where my <?php echo base_url()?> is not linking to the form_validation page as it should. 我遇到了一个问题,我的<?php echo base_url()?>未正确链接到form_validation页。 I have the config.php set to $config['base_url'] = ''; 我将config.php设置为$config['base_url'] = ''; and the autoload.php set to $autoload['helper'] = array('url', 'form', 'html'); 并将autoload.php设置为$autoload['helper'] = array('url', 'form', 'html'); So I don't understand why I am getting the 404 error. 所以我不明白为什么会出现404错误。 Any help would be greatly advised. 任何帮助将不胜感激。

Model_ca.php Model_ca.php

<?php

class Model_ca extends CI_Model {

function __construct()
    {

    parent::__construct();
    }

}

 ?>

View_ca.php View_ca.php

 <html>
     <head> 
     <title>Add Chipper to Database</title>
     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
      rel="stylesheet">
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      </head>
     <body>
         <div class="container">
             <h3 align="center">Add Chipper to Database</h3>
             <!--Link form to base url which is defined in autoload.php-->
             <form method="post" action="<?php echo base_url()?>Controller_ca/form_validation">

               <div class="form-group">  
             <label>Enter Name</label>    
                <input type="text" name="name" class="form-control"/>
                </div>

                <div class="form-group">
                <label>Enter Location</label>    
                <input type="text" name="location" class="form-control"/>
                </div>

                <div class="form-group">
                <label>Enter Description</label>    
                <input type="text" name="description" class="form-control"/>
                 </div>

                 <div class="form-group">
                 <input type="submit" name="insert" value="Add Chipper" class="btn btn-info"/>
                 </div>

             </form>
         </div>

     </body>
 </html>

Controller_ca.php Controller_ca.php

<?php

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

class Controller_ca extends CI_Controller {

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

    }

    public function index() 
    {  
        $this->load->view('View_ca');
    }    


public function form_validation()
{
    echo 'Form Validation is Working!';
}


}
?>  

Config Should be Config应该是

$config['base_url'] = 'http://localhost/path/to/folder/';

.htaccess should be .htaccess应该是

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Make sure rewrite rule is enabled in php.ini 确保在php.ini中启用了重写规则

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

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