Postingan lainnya
Memanggil method private di models dari controller
Tolong bantuannya gan. saya baru belajar CI. disini saya ingin membuat sistem login. saya ingin memanggil method login (private) yang ada di model dari controller. tapi saya mendapatkan error
pada controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('User_model');
$this->load->library('form_validation');
}
public function index()
{
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if ($this->form_validation->run() == FALSE) {
$data['title'] = 'Halaman Login';
$this->load->view('templates/auth_header', $data);
$this->load->view('auth/login');
$this->load->view('templates/auth_footer');
}else{
$this->_login();
}
}
pada models
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User_model extends CI_Model
{
private function _login()
{
$email = $this->input->post('email');
$password = $this->input->post('password');
$user = $this->db->get_where('user', ['email' => $email])->row_array();
if ($user) {
........
0
Tanggapan
tujuannya private untuk apa?
1 Jawaban:
kalau tidak ada alasan khusus, dibuat public saja, tidak perlu private
0