Welcome Guest, Not a member yet? Register   Sign In
problem with refresh data
#1

[eluser]cipherz[/eluser]
function index() {
//connect database and retrieve list of item
}

function create() {
// page with form to input data
}

function do_create_item {
// insert data to database
redirect('index');
}

this is my piece of code. I'm using CI2.0. I have a problem when i insert data into database
and redirect back to index page. The new data doesn't appear after the redirect to index page
but i have to press refresh button of browser before the item appear.

Can anybody help what is the problem here?
Thank you in advance.....
#2

[eluser]mi6crazyheart[/eluser]
I think this codes are from u'r controller class file and by using "redirect(‘index’);" u might've wanted to redirect the control to u'r "function index()" of u'r controller file. Am i right... ?
#3

[eluser]cipherz[/eluser]
I'm redirecting to controller/index

This piece of code working in CI 1.7 so im just wondering what could be wrong
#4

[eluser]mi6crazyheart[/eluser]
Ok, if this is the thing the i think this will help u...
Code:
redirect(‘controller-file-name’,'refresh');

for more info: http://ellislab.com/codeigniter/user-gui...elper.html
#5

[eluser]cipherz[/eluser]
It doesnt help with 'refresh' as well =(
#6

[eluser]mi6crazyheart[/eluser]
After using the above redirect code where CI is taking to u ? Can u show u'r controller code also... ?
#7

[eluser]cipherz[/eluser]
<?php

class Member extends Controller {

var $folder = 'member/';
function Member ()
{
parent::Controller();
}

function index()
{
$this->load->model('Member');
$data['list'] = $this->Member->list();
$main['content'] = $this->load->view($this->folder.'index', $data, true);
$this->load->view($this->folder.'layout', $main);
}

function create()
{
$main['content'] = $this->load->view($this->folder.'create', array(), true);
$this->load->view($this->folder.'layout', $main);
}

function do_create_item()
{
$this->load->model('Member');
$data['firstname'] = $this->input->post('firstname');
$data['lastname'] = $this->input->post('lastname');

$this->Member->create($data);
redirect($this->folder.'index');
}
}

index page - list all members
create page - form to input data : firstname and lastname and save button
do_create_item - action to insert member to database

once press save button it redirect to index page but the new record doesnt show up i do have to press refresh button bfore the item appear.
#8

[eluser]mi6crazyheart[/eluser]
Can u say , what's the logic behind of doing this...
Code:
$main[‘content’] = $this->load->view($this->folder.‘index’, $data, true);
$this->load->view($this->folder.‘layout’, $main);
#9

[eluser]cipherz[/eluser]
i have the view file layout.php and index.php in the containing folder. layout.php is kind of wrapper which include menu and footer $main['content'] will hold the content which will change accordingly to each page.
#10

[eluser]mi6crazyheart[/eluser]
Try this & tell me what's happening :

Code:
function index()
  {
      $this->load->model(‘Member’);
      $main[‘content’] = $this->Member->list();  
      $this->load->view('member/layout', $main);
  }




Theme © iAndrew 2016 - Forum software by © MyBB