Lhynx
Lhynx

Reputation: 89

Error in redirecting page in Codeigniter

I'd like to ask some help about redirecting a page..What I want is after I add a data I want my page to be direct to a certain page where all products where displayed.. The link I'm expecting is

'http://localhost/CrudApp/index.php/GetProductController' , but what I'm getting at is this:

'http://localhost/CrudApp/index.php/index.php/index.php/GetProductController' resulting a 404 Page not found.. please, some help. Thanks in advance..

here is my code:

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>

and my controller: 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');
}

i also configure my config.php, my baseurl is 'index.php'

Upvotes: 0

Views: 4013

Answers (2)

John Busca Longe
John Busca Longe

Reputation: 51

Svetlio is right. Also if you are talking about product you shoul create a product Controller and inside this controller you set all your functions: add, edit, awesomefunction, whatever...

So you can do it like:

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

or

redirect('products/where_you_want_go_function');

Upvotes: 0

Svetoslav
Svetoslav

Reputation: 4686

The correct way for routing at CI is to write :

CLASS/METHOD So in your case you must write

redirect('GetProductController/index');

Other option is to set different functions at 1 controller and to access them as: (When we talk for the same "products")

Product/set
Product/get

There is no logic point to make controllers for each different ACTION for the same Item.

Upvotes: 0

Related Questions