strong text i want to echo user who created data but seems it is possible?somebody know this issue?
This is my controller
class Auth extends CI_Controller {
public function index(){
$data['users'] = $this->User_model->get();
$this->load->view('login_page');
}
public function login(){
$email = $_POST['email'];
$password = $_POST['password'];
$data = $this->User_model->login ($email, $password);
if($data){
$this->session->set_userdata('user', $data);
redirect('Users');
}
else{
header('location:'.base_url().$this->index());
Echo 'error';
}
}
}
This is my model
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($email, $password){
$query = $this->db->get_where('users', array('email'=>$email, $data['password'] = password_hash($data['password'],PASSWORD_DEFAULT))) ;
return $query->row_array();
}
}
This is my view Where i want to echo the user in created by textbox below. Anyone have an idea?
<
!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Roles</title>
</head>
<body>
<h1>Roles</h1>
<div class="container">
<form method="post" action="<?php echo site_url('roles/add')?>" >
<label>Code</label>
<input type="text" name="code" placeholder="Code">
<label>Description</label>
<input type="text" name="description" placeholder="Description">
<label>Permissions</label>
<input type="text" name="permissions" placeholder="Permissions">
<!-- created By -->
<label>Created by</label>
<input type="text" name="created_by" placeholder="Name">
<button type="submit" value="save" >Submit</button>
</form>
</div>
</body>
</html>
In your controller use method like :
$data = $this->User_model->login($email, $password);
Now in Modal :
public function login($email,$password){
$password = password_hash($password,PASSWORD_DEFAULT);
$query = $this->db->get_where('users', array('email'=>$email, 'password'=>$password));
return $query->row_array();
}
Hope it may help :)