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

查看:57
本文介绍了php echo base_url()带我到404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照此教程进行表单,以将数据插入到我的数据库中。我遇到了一个问题,我的<?php echo base_url()?> 没有按原样链接到form_validation页。我将config.php设置为 $ config ['base_url'] =''; 并将autoload.php设置为 $ autoload ['helper '] = array('url','form','html'); 所以我不明白为什么会收到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. I have the config.php set to $config['base_url'] = ''; and the autoload.php set to $autoload['helper'] = array('url', 'form', 'html'); So I don't understand why I am getting the 404 error. Any help would be greatly advised.

<?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['base_url'] = 'http://localhost/path/to/folder/';

.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]




确保在php.ini中启用了重写规则

Make sure rewrite rule is enabled in php.ini

这篇关于php echo base_url()带我到404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆