在Codeigniter中重定向页面时出错


Error in redirecting page in Codeigniter

我想问一些关于重定向页面的帮助..我想要的是我添加一个数据后,我希望我的页面直接到某个页面,所有的产品在哪里显示..我期待的链接是

'http://localhost/CrudApp/index.php/GetProductController',但我想说的是:

'http://localhost/CrudApp/index.php/index.php/index.php/GetProductController'导致404页面未找到…请帮帮我。提前感谢……

下面是我的代码:

AddProduct.php

    <form method="POST" action="SaveProductController"></br></br></br>
        <table border='1' align='center'>
            <tr>
                <td>ID: </td><td><input type="text" name="id" 
                                        value="<?php echo $GetProductId->id + 1; ?>" readonly="readonly"></td>
            </tr>
            <tr>
                <td>Description: </td><td><input type="text" name="description"></td>
            </tr>
            <tr>
                <td>Price: </td><td><input type="text" name="price"></td>
            </tr>
            <tr>
                <td>Size: </td><td><input type="text" name="size"><td>
            </tr>
            <tr>
                <td>Aisle: </td><td><select name="aisle">
                        <?php
                        foreach ($GetAisle as $row) {
                            printf("<option value='" . $row['id'] . "'>" . $row['description'] . "</option>");
                        }
                        ?>
                    </select></td>
            </tr>
            <tr>
                <td></td><td><input type="submit" name="addProduct" value="Add Product"><td>
            </tr>
        </table>
    </form>

和我的控制器:SaveProductController.php

function index() {
    $this->load->model('ProductDao');
    $id = $this->input->post('id');
    $description = $this->input->post('description');
    $price = $this->input->post('price');
    $size = $this->input->post('size');
    $aisle = $this->input->post('aisle');
    //$this->ProductDao->saveProduct($id, $description, $price, $size, $aisle);
    redirect('/GetProductController');
}

我也配置我的config.php,我的baseurl是'index.php'

Svetlio是对的。此外,如果你谈论的是产品,你应该创建一个产品控制器,并在这个控制器中设置所有的功能:添加,编辑,awesomefunction,等等。

你可以这样写:

redirect(site_url('products/where_you_want_go_function'));

redirect('products/where_you_want_go_function');

在CI中路由的正确方法是:

类/方法在你的例子中,你必须写

redirect('GetProductController/index');

另一种选择是在一个控制器上设置不同的功能,并以如下方式访问它们:(当我们谈论相同的"产品"时)

Product/set
Product/get