在Codeigniter中重定向页面时出错

时间:2012-12-27 14:57:37

标签: php 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'

2 个答案:

答案 0 :(得分:0)

在CI处路由的正确方法是写:

类/方法 所以在你的情况下你必须写

redirect('GetProductController/index');

其他选项是在1个控制器上设置不同的功能,并将其作为: (当我们谈论相同的“产品”)时,

Product/set
Product/get

为同一个项目的每个不同的ACTION制作控制器没有逻辑点。

答案 1 :(得分:0)

Svetlio是对的。此外,如果您正在谈论产品,您应该创建一个产品控制器,并在此控制器内部设置所有功能:添加,编辑,功能强大,无论如何......

所以你可以这样做:

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

redirect('products/where_you_want_go_function');