I have my crud which is I want to upgrade it which is I want to echo the user who created another user account. This is my controller to add the user.
public function add()
{
$this->data['page_title'] = "Add User";
$input_data = $this->input->post();
if(!empty($input_data))
{
$this->User_model->insert($input_data);
redirect('/users');
} else {
$this->load->view('templates/master', $this->data);
}
}
Below is my model for populate the user information.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model {
private $_table = "users";
public function get( $id = false )
{
if ($id) {
$this->db->where('id =', $id);
$query = $this->db->get($this->_table);
return $query->row_array();
}
$query = $this->db->get($this->_table);
return $query->result_array();
}
public function insert($data)
{
$data['password'] = password_hash($data['password'],PASSWORD_DEFAULT);
$this->db->insert($this->_table, $data);
}
public function update($data)
{
$id = $data['id'];
unset($data['id']);
$data['password'] = password_hash($data['password'],PASSWORD_DEFAULT);
$this->db->where('id =', $id);
$this->db->update($this->_table, $data);
}
public function delete($id)
{
$this->db->where('id', $id);
$this->db->delete($this->_table);
}
public function login($username, $password){
$query = $this->db->get_where('users', array('username'=>$username, $data['username'] = password_hash($data['password'],PASSWORD_DEFAULT))) ;
return $query->row_array();
}
}
This is my text field(created by) view which is I want to auto echo the user who created the data.
<div class="col-sm-6">
<label>Created By</label>
<input type="text"required class="form-control form-control-user" name="created_by" placeholder="Created By"required>
</div>