[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:
<?php echo anchor('users/edit' .'/'. $user->user_id, '<div class="btn btn-primary"><i class="fa fa-edit"></i> Edit</div>');?>
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:
<?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:
<?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;
}
}
}