CI 묻고 답하기

제목 기본로직에서 로그인세션처리가 잘 안됩니다.
카테고리 CI 2, 3
글쓴이 venven 작성시각 2018/05/17 20:25:53
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 11237   RSS

1. controller

class User extends CI_Controller {

    public function __construct()

    {

        parent::__construct();

        $this->load->model('user_model');

        $this->load->helper(array('form', 'url'));

        $this->load->library(array('session', 'form_validation'));

    }

    public function index()

    {

        $this->login();

    }

    public function login()

    {        

        $ou_id = $this->input->post('ou_id');

        $ou_pw = $this->input->post('ou_pw');    

        $this->form_validation->set_rules('ou_id', '아이디', 'trim|required');

        $this->form_validation->set_rules('ou_pw', '비밀번호', 'trim|required|md5');        

        if ($this->form_validation->run() == FALSE)

        {            

            $this->load->view('login');

        }

        else

        { 

            if ($user = $this->user_model->get_user_login($ou_id, $ou_pw))

            {   

                

//                echo $user['ou_nick']."------------";

                $user_array = array(

                'ou_nick' => $user['ou_nick'],

                'is_logged_in' => true

               

                );

                $this->session->set_userdata('userdata', $user_array);

                redirect('main');                

            }

            else

            {

              $this->user_model->set_userloginlog($ou_id, '로그인에러');

                redirect('user/login');

            }

        }

    }

    

}

 

2. model

class User_model extends CI_Model

 {

    public function __construct()

    {

        $this->load->database();

    }

    

    public function get_user_login($ou_id, $ou_pw)

    {

        $query = $this->db->get_where('planner_user', array('ou_id' => $ou_id, 'ou_pw' => $ou_pw));        

        if($this->db->affected_rows() == 1){

            $row = $query->row();

            return $row;

        }else{

            error_log('존재하지 않는 아이디입니다.('.$ou_id.')');

            return false;

        }

                

    }

    

}

3. view

<?php

$user_data = $this->session->userdata('userdata');

?>

<li><a href="#">*<?php echo $user_data['ou_nick']; ?>*</a> 님이 로그인하셨습니다.</li>

 

이런 소스로 작업중입니다.

그런데 controller에서 echo를 찍어보면

model에서 select 한 데이타가

controller에서 echo 로 찍어보면, 데이타가 들어오지 않고 있습니다.

실제 select를 한 구문은 1개의 레코드를 찾은것 같은데...

controller쪽에서, model에서 받은 데이타를 찍어보면..아무값도 없습니다.

//  <- 주석처리한 부분에서, 실제 넘어온 값을 확인해볼려고합니다만

어디가 문제인지 모르겠습니다.

그러다보니, 당연히 view단에서도 데이타가 넘어오지 않구요...

고수님들의 지도 부탁드립니다.

감사합니다.

 

 다음글 ajax 통신 문의드립니다 ㅠ.ㅠ (15)
 이전글 파일업로드에 관해서 질문합니다. (1)

댓글

변종원(웅파) / 2018/05/18 11:15:09 / 추천 0

$query = $this->db->get_where('planner_user', array('ou_id' => $ou_id, 'ou_pw' => $ou_pw));        

        if($this->db->affected_rows() == 1){

 

위 상태면 쿼리 실행이 안된겁니다. 쿼리만 선언하고 실행을 안한 것이라 당연히 존재하지 않은 아이디라고 나옵니다.

쿼리 실행하고 affected_rows() 실행하세요.

venven / 2018/05/19 07:03:46 / 추천 0
아....감사합니다...다시 처리해보겠습니다..