Welcome Guest, Not a member yet? Register   Sign In
Updating the user info?
#1

[eluser]riwakawd[/eluser]
I would like to know best way to make sure I update the correct user. And still get my update form to show. I get 404 error page not found.


Currently when I click on the user edit button it shows in url.
Code:
http://localhost/codeigniter/codeigniter-blog/admin/users/edit/1
which is correct. 1 is id

Code:
$route['users/edit'] = "users/users/edit";

When I click on my user edit button
Code:
&lt;?php echo anchor('users/edit' .'/'. $user->user_id, '<div class="btn btn-primary"><i class="fa fa-edit"></i> Edit</div>');?&gt;


It still does not show my update getForm for that user. How do I make form show and only make sure updating that users info.
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {

public function __construct() {
  parent::__construct();

  $this->load->library('user');

  if ($this->session->userdata('isLogged') == TRUE) {
    
   return true;
  
  } else {

   redirect('/');

  }
}

public function index() {
  $this->getList();
}

public function edit() {

  $this->load->library('form_validation');

$this->load->model('users/model_user');

$this->form_validation->set_rules('name', 'Name');
$this->form_validation->set_rules('username', 'Username');

if ($this->form_validation->run() == TRUE) {
redirect('users');
} else {
$this->getForm();
}
}

function getForm() {
  $data['title'] = "Users";

  $data['base'] = config_item('HTTP_SERVER');

  $data['isLogged'] = $this->user->isLogged();

  $this->load->model('users/model_user');

  $data['users'] = $this->model_user->getAll();
  
  $data['header'] = $this->load->view('template/common/header', $data, TRUE);
  $data['footer'] = $this->load->view('template/common/footer', NULL, TRUE);

  return $this->load->view('template/users/users_form', $data);
}

function getList() {
  $data['title'] = "Users";

  $data['base'] = config_item('HTTP_SERVER');

  $data['isLogged'] = $this->user->isLogged();

  $this->load->model('users/model_user');

  $data['users'] = $this->model_user->getAll();

  $data['header'] = $this->load->view('template/common/header', $data, TRUE);
  $data['footer'] = $this->load->view('template/common/footer', NULL, TRUE);

  return $this->load->view('template/users/users_list', $data);
}

}

Model

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_user extends CI_Model {

function getAll() {
  $query = $this->db->get('user');

  if ($query->num_rows() > 0) {

   return $query->result();
   return true;
  } else {
   return false;
  }
}
}


#2

[eluser]InsiteFX[/eluser]
Code:
$route['users/edit/(:num)'] = "users/users/edit/$1";

You also need to pass the id into any method that you call.
#3

[eluser]riwakawd[/eluser]
[quote author="InsiteFX" date="1411336304"]
Code:
$route['users/edit/(:num)'] = "users/users/edit/$1";

You also need to pass the id into any method that you call.
[/quote]

I have got the route working now. For passing the user id what would you recommend.

I have tried with no luck

example on edit function
Code:
function edit($user_id = 0) {

$this->load->model('users/model_user');

$user_id = $this->model_user->getID($user_id);



$this->load->library('form_validation');

$this->form_validation->set_rules('name', 'name');
$this->form_validation->set_rules('username', 'username');
$this->form_validation->set_rules('email', 'email');
$this->form_validation->set_rules('password', 'password');
$this->form_validation->set_rules('confirm_password', 'confirm_password');

if ($this->form_validation->run() == TRUE) {
  redirect('users');
} else {
  $this->getForm();
}

}

model

Code:
public function getID() {
           $query = $this->db->get('user');

            if ($query->num_rows() == 1) {
              
                  return  $query->row('user_id', $user_id);

                  return true;

            } else {

                  return false;

            }
      }
#4

[eluser]InsiteFX[/eluser]
You also need to pass the user_id into your edit method.

In your form you can use a hidden field to store the user_id and use set_value to set it,
or use a session variable to get it.





Theme © iAndrew 2016 - Forum software by © MyBB