簡體   English   中英

在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'

在CI進行路由的正確方法是:

班級/方法所以你必須寫

redirect('GetProductController/index');

另一種選擇是在1個控制器上設置不同的功能,並按以下方式訪問它們:(當我們談論相同的“產品”時)

Product/set
Product/get

沒有邏輯點可以使同一項目的每個不同ACTION的控制器。

Svetlio是正確的。 同樣,如果您在談論產品,則應創建一個產品控制器,並在該控制器內設置所有功能:添加,編輯,很棒的功能等等。

所以你可以這樣做:

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

要么

redirect('products/where_you_want_go_function');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM