Php Codeigniter提供了错误的url

Php Codeigniter提供了错误的url,php,html,codeigniter,Php,Html,Codeigniter,这是我给Codeigniter的代码。我正处在一个非常难熬的阶段,所以请容忍我 在我的控制器文件夹中:Users.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Users extends CI_Controller { function __construct() { parent::__construct(); $this->load-&g

这是我给Codeigniter的代码。我正处在一个非常难熬的阶段,所以请容忍我

在我的控制器文件夹中:Users.php

<?php  

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

class Users extends CI_Controller {

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

public function index()  {  
    $data['user_list'] = $this->Users_model->get_all_users();  
    $this->load->view('Show_users', $data);  
} 


public function add_form()  {  
    $this->load->view('Insert');  
}

public function insert_new_user()  {  
    $udata['name'] = $this->input->post('name');  
    $udata['email'] = $this->input->post('email');  
    $udata['address'] = $this->input->post('address'); 
    $udata['mobile'] = $this->input->post('mobile');  
    $res = $this->users_model->insert_users_to_db($udata);  
    if($res){  
        header('location:'.base_url()."index.php/Users/".$this->index());  
    }  
} 
}

?>
我的代码应该带我到
http://127.0.0.1/ci_beginning/index.php/users/add_form
**请注意“用户”中的“s”,因为我在

这让我想到了这一点:
http://127.0.0.1/ci_beginning/index.php/user/add_form

为了让我进入add_表单以显示Insert.php视图,我需要转到地址栏并将“s”插入到“user”中,这样就不会出现页面未找到错误


请指出我错在哪里。感谢您的耐心。

您需要在CI3中设置基本url

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/

$config['base_url'] = 'http://localhost/yourproject/';
其他明智的做法是在url中显示ip

在config.php上,您可以添加

if (isset($_SERVER['HTTP_HOST'])) {

    $HTTP_SERVER = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $HTTP_SERVER .= '://'. $_SERVER['HTTP_HOST'];
    $HTTP_SERVER .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} else {

    $HTTP_SERVER = 'http://localhost/';
}

define('HTTP_SERVER', $HTTP_SERVER);

unset($HTTP_SERVER);

$config['base_url'] = HTTP_SERVER;

您的表单正在发布到index.php。您必须调用类和函数

取代

Action="<?php echo base_url('index.php/users/insert_new_user'); ?>"
Action=“”

假设您已经配置了基本URL。就像下面评论中提到的那样,我把它放在我的config/config.php'config['base_url']=';'对于locaIhost前面的http://我仍然会遇到相同的错误。因为我要定义$config['base\u url']=http\u SERVER;,我需要删除config.php顶部的默认$config['base_url']='localhost/ci_start/'吗?太糟糕了,Wolfgang删除了他的响应,但他是对的。我需要配置config.php并添加“$config['base_url']=”;”谢谢沃尔夫冈。我把它删除了。另外,我注意到您的表单open没有设置为正确的函数
action=“index.php/users/insert\u new\u user”
,并且您不需要使用
?>
Ohh关闭控制器或模型,您的标题中有一个index.php。因此,在cofig folder中配置cofig.php文件注意,您已经在表单中调用了模型。不是控制器
Insert New User 
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/

$config['base_url'] = 'http://localhost/yourproject/';
if (isset($_SERVER['HTTP_HOST'])) {

    $HTTP_SERVER = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $HTTP_SERVER .= '://'. $_SERVER['HTTP_HOST'];
    $HTTP_SERVER .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

} else {

    $HTTP_SERVER = 'http://localhost/';
}

define('HTTP_SERVER', $HTTP_SERVER);

unset($HTTP_SERVER);

$config['base_url'] = HTTP_SERVER;
Action="<?php echo base_url('index.php/users/insert_new_user'); ?>"