Welcome Guest, Not a member yet? Register   Sign In
Controller Calling Function Conflict with browser URL
#1

[eluser]zombica[/eluser]
Hi guys in my insertion of a form the action of controller which i called is user/add_user.

Here is my that USER controller class with two following functions to whom i am calling....

function add_user(){
/// set page title
$this->data['title'] = 'Add User';
$this->load->vars($this->data);
/*** Validation*****/
$rules['fname'] = "trim|required";
$rules['lname'] = "trim|required";
$rules['username'] = "trim|required";
$rules['password'] = "trim|required|min_length[6]";
$rules['password'] = "trim|required|matches[conf_pass]";
$rules['conf_pass'] = "trim|required";
$rules['email'] = "trim|required|valid_email";
//$rules['description'] = "required";
$this->validation->set_rules($rules);
$this->validation->set_error_delimiters('<li class="errorLi">', '</li>');
$fields['fname'] = 'first name';
$fields['lname'] = 'last name';
$fields['username'] = 'username';
$fields['description'] = 'description';
$fields['email'] = 'email';
$this->validation->set_fields($fields);
if($this->input->post('mode')=='insert')
{
$username=$this->input->post('username');
$q = "SELECT * from tms_user
where username = '".$username."'";
$query = mysql_query($q);
if ($rows=mysql_num_rows($query) > 0)
{
$this->validation->error_string ='Username You entred is not available';
$_data['error'] = $this->validation->error_string;
$_data=$this->load_leftmenu();/// common function that loads the left menu panel for each view page
$_data['userType']=$this->usermodel->get_user_types(4,0);
$this->load->view("/adduser",$_data);
}
}
if ($this->validation->run() == FALSE)
{
$_data=$this->load_leftmenu();
$_data['userType']=$this->usermodel->get_user_types(4,0);
$this->load->view("/adduser",$_data);
}
else
{
$this->usermodel->user_insert();
$this->users_view();
}
exit;

}


After successful insertion i call a function users_view(); which shows me the record recently inserted.
Here is that function....

function users_view(){

/// set page title
$this->data['title'] = 'View Users Records ';
$this->load->vars($this->data);

/******Paginating Records********/
$rows=$this->db->count_all("tms_user");
$base=base_url();
$config['base_url'] =base_url().$this->config->item('index_page').'/'.'users/users_view';
$config['total_rows'] = $rows;
$config['per_page'] = '5';
$config['uri_segment'] = 3;
$config['num_links'] = 4;
$config['first_link'] = '«';
$config['last_link'] = '»';
$config['next_link'] = '>';
$config['prev_link'] = '<';
$this->pagination->initialize($config);

/*******************************/
$data=$this->load_leftmenu();
$user_id = $_SESSION['user_id'];
$data['alluserList'] = $this->usermodel->get_all_user($config['per_page'],$this->uri->segment(3),$user_id);
$this->load->view('users_view',$data);
exit;
}

Now problem comes here once i press form submit button browser URL contains the
following url:

http://dev1/web/tms_v1/index.php/users/add_user

but the following page displayed contains the users_view page which is a clear cut conflict beween two controller functions calling. Here if i presses F5 it reinsert the record again because above URL resend the request of new record insertion i.e "users/add_user". How does this URL will be change.

As far as i have concluded the problem is in users_view() function because here the view page i have loaded is like this:
$this->load->view('users_view',$data)
if i change this to
$this->load->view('users/users_view',$data)

it throws me following error

An Error Was Encountered

Unable to load the requested file: users/users_view.php

Any one can help in this regrard....

Thanks.
Regards,
Zombica
#2

[eluser]SardiorDragon[/eluser]
Code:
if ($this->validation->run() == FALSE)
      {
          $_data=$this->load_leftmenu();
          $_data[‘userType’]=$this->usermodel->get_user_types(4,0);              
          $this->load->view(”/adduser”,$_data);
      }
      else
        {
          $this->usermodel->user_insert();
          $this->users_view();
        }

My guess to why you are seeing the results of users_view is above. The validation ends up being TRUE so the validation->run() returns true which leads to the else statement.

Quote:As far as i have concluded the problem is in users_view() function because here the view page i have loaded is like this:
$this->load->view(‘users_view’,$data)
if i change this to
$this->load->view(‘users/users_view’,$data)

it throws me following error
An Error Was Encountered

Unable to load the requested file: users/users_view.php

You are getting this error because in your views folder you do not have a users folder. Make a users folder and then add the users_view.php file to it and the error should go away.




Theme © iAndrew 2016 - Forum software by © MyBB