表单提交 - CodeIgniter

时间:2015-08-07 07:18:43

标签: php codeigniter

如果我打开〜/ index.php / crud /,提交表单,它会显示这个url:〜/ index.php / index.php / crud / create。 您可以从页面源中看到这一点。 我很奇怪为什么有两个index.php?

class Crud extends CI_Controller
{
function index()
{
        $this->load->view('crud');
}

function create()
{
    $data = array(
        'sku' => $this->input->post('sku'),
        'name' => $this->input->post('name'),
        'price' => $this->input->post('price')
        );

        $this->load->model('crud_model');
        $this->crud_model->create($data);
        $this->index();
}
}

class Crud_model extends CI_Model
{
function create($data)
{
    $this->db->insert('products', $data);
    return;
}
}

<!DOCTYPE html>
<html>
<head>
<title>CRUD</title>
</head>
<body>
<h1>Create</h1>
<div>
    <?php echo form_open('crud/create'); ?>
        <label for="sku">SKU</label>
        <input type="text" name="sku" id="sku"><br>
        <label for="name">Name</label>
        <input type="text" name="name" id="name"><br>
        <label for="price">Price</label>
        <input type="text" name="price" id="price"><br>
        <input type="submit" name="submit" value="Go">
    <?php echo form_close(); ?>
</div>
</body>
</html>

如果我打开〜/ index.php / crud /,提交表单,它会显示这个url:〜/ index.php / index.php / crud / create。 您可以从页面源中看到这一点。 我很奇怪为什么有两个index.php?

1 个答案:

答案 0 :(得分:0)

将其修改为吼叫。

    <!DOCTYPE html>
    <html>
     <head>
   <title>CRUD</title>
 </head>
        <body>
       <h1>Create</h1>
    <div>
 <?php echo form_open(base_url().'crud/create'); ?>
    <label for="sku">SKU</label>
    <input type="text" name="sku" id="sku"><br>
    <label for="name">Name</label>
    <input type="text" name="name" id="name"><br>
    <label for="price">Price</label>
    <input type="text" name="price" id="price"><br>
    <input type="submit" name="submit" value="Go">
<?php echo form_close(); ?>
   </div>
    </body>
    </html>
相关问题