CI 묻고 답하기

제목 CI 초보 질문드립니다.
글쓴이 Cristy 작성시각 2015/09/24 12:30:53
댓글 : 4 추천 : 0 스크랩 : 0 조회수 : 18767   RSS
일단 컨트롤러
load->model('Main_model');
		$this->load->helper('url_helper');
	}

	public function index()
	{
		$this->form_validation->set_rules('id', "아이디", "trim|required|min_length[4]");
		$this->form_validation->set_rules('pwd', "비밀번호", "trim|required|min_length[4]");
		if (false == $this->form_validation->run()) {
			
			$this->load->view('/Main');
		}
		else {
			$hash_pass = $this->input->post('pwd');
			//$hash_pass = password_hash($hash_pass, PASSWORD_BCRYPT);
			$id = $this->input->post('id');
			$logchk = $this->Main_model->select(array(
					'id' => $id,	
					'pwd'=>$hash_pass
				));
			redirect('Main','refresh');
			if($logchk) {
				$S_id = $this->session->userdata('user_id');
			}
		}
	}
	public function logout() {
		$this->session->sess_destroy();
		redirect('/Regist','refresh');
	}
	public function regist() {
		redirect('/Regist','refresh');
	}
}

model
db->query($sql, array($id, $pwd));
        
        $data = $rst->row();
        
        if( isset($data->id) ) {
            $this->session->set_userdata(array('user_id' => $data->id, 'user_name' => $data->name));
           return TRUE;
        }

    }
}

view
 
<!DOCTYPE html>
<?php
$sid = $this->session->userdata('user_id');
?>
<html>

  <head>

    <title> /</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" type="text/css" href="/Common/CSS/style.css">
    <!-- 부트스트랩 -->

    <link href="/Common/Bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">

  </head>

  <body>
	
    <div align="right" style="margin-top:10px;">
    	<!--로그인 회원가입 id/pw찾기-->
      <form method="post">
      	<table align="right">
      		<tr>
  		    	<td style="font-size:10px;padding-right:10px;">
            <?php if(!$sid) {?>
  			    	<label>ID : </label>
              <input type="text" name="id" size="10">
  			    	<label>PWD : </label>
  			    	<input type="password" name="pwd" size="10">
  			    	<button type="submit">로그인</button>
  			    	<button name="regist">회원가입</button>
  			    	<button name="FindMem">ID/PW찾기</button>
              <?php } else { ?>
              <button name="logout" onclick="location.href='Regist/index()'">로그아웃</button>
              <?php }?>
  		    	</td>
  	    	</tr>
      	</table>
      </form>
      <br><hr>

    </div>

    <!-- jQuery (부트스트랩의 자바스크립트 플러그인을 위해 필요한) -->

    <script src="//code.jquery.com/jquery.js"></script>

    <!-- 모든 합쳐진 플러그인을 포함하거나 (아래) 필요한 각각의 파일들을 포함하세요 -->

    <script src="/Common/Bootstrap/js/bootstrap.min.js"></script>

    <!-- Respond.js 으로 IE8 에서 반응형 기능을 활성화하세요 (https://github.com/scottjehl/Respond) -->
	
	<div>
		
	</div>
  </body>

</html>

아직 이정도까지밖에 안하긴 했는데.. 지금 이상태에서 로그인세션을보고 로그인까지는 잘되거든요

근데 회원가입페이지로 넘어가기 위해서 onclick="location.href='/Main/regist()';"를 하면 함수실행이 될 줄 알았는데 안되네요 ㅠ.ㅠ... 혹시 view파일 하나에서 버튼이 많을때 버튼클릭시 페이지 이동하는 방법이 다른것인가요..?
 다음글 CI에서의 $this 는 무엇을 의미하나요? (3)
 이전글 uri 라우팅 질문입니다. (1)

댓글

jeff / 2015/09/24 14:28:51 / 추천 0
앵커태그 쓰면 간단하게 될텐데요..
<a href="/main/regist">회원가입</a>
 
생각생각 / 2015/09/24 15:18:50 / 추천 0
regist 뒤에 ()만 빼주시면 될것 같은데 아닌가요?
phpbug / 2015/09/24 17:11:59 / 추천 0
정의되어있는 regist 함수가 없는데요?
function regist(){
location.href='http://www.example.com/';
}
Cristy / 2015/09/24 19:54:40 / 추천 0
@jeff 님 감사합니다 댓글을보기전에 해결하긴했지만..

@생각생각 님 ()을빼도안되더라구요 ..

@phpbug 님 컨트롤러에 보시면 맨마지막에 함수가 있긴합니당..

안되던 이유는 button태그때문이더라구요.. input type="button"으로 해버리니 잘 실행이 되더군요..