Reputation: 27
I've already tried the other codeigniter redirect not working topics, but they have different issues than mine.
This is the one where I put my redirect.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class SampleView extends CI_Controller {
public function index() {
$data['title'] = 'Home';
$this->load->view('includes/header', $data);
$this->load->view('pages/index');
$this->load->view('includes/footer');
}
public function update() {
$data = array(
'item_id' => $this->input->post('i_id', true),
'item_name' => $this->input->post('i_name', true),
'item_price' => $this->input->post('i_price', true),
'item_description' => $this->input->post('i_description', true),
);
$this->sampleviewmodel->update($data);
redirect('sampleview/items');
}
}
This is the form that will link to update function.
<form method="POST" action="<?=$this->config->base_url();?>sampleview/update">
This is my config.php
$config['base_url'] = 'http://localhost/w31_ton';
And this is my htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /w31_ton
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
PS. It all works fine, my only problem is that it won't redirect to the page I want.
Upvotes: 0
Views: 495
Reputation: 3714
You have to load URL helper file before calling redirect()
function for the redirect to work. Inside update function, add - $this->load->helper('url');
. That should fix that.
Upvotes: 2