CI 묻고 답하기

제목 컨트롤러 링크 관련
글쓴이 kashou 작성시각 2012/11/21 10:36:49
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 15791   RSS
 php와 CI를 만진지 얼마 안되어서 미숙한 부분이 베리베리베리 많아요 -_ㅠ 
그 부분에 대해서는 양해를 부탁 드립니다 ㅠㅅㅠ

로그인 및 간단한 회원 등록을 만들고 있습니다.
기존에 php + html 코드로 했던 것을 MVC 방식으로 나누어서 하고 있어요.

Controller - index() 에서 첫페이지인 로그인 화면 뷰를 불러옵니다.
그 곳에서는 아이디 + 비밀번호 입력받고 로그인을 하는 기능과 회원등록을 할 수 있도록 했구요.

지금 어찌어찌해서 회원가입은 구현했는데 회원 
가입 후 다시 index 화면으로 돌아오고 나서 다시 entry를 누리면 주소값이 늘어납니다.

기존 : http://localhost/121120_Page/index.php/Login/
가입 후 index 로드되면서 다시 엔트리버튼 누르면 : 
1-1 : http://localhost/121120_Page/index.php/Login/process_entry
1-2 : http://localhost/121120_Page/index.php/Login/Login/entry_view

이렇게 바뀝니다 ㅠ스ㅠ 
http://localhost/121120_Page/index.php/Login/ 얘만 고정적으로 두고 ./컨트롤러 함수명을 적어야 정상적으로 바뀔 것 같은데 ㅠㅠ 어떻게 하면 될까요..


* 모델 : member_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 class Member_model extends CI_Model
 {
  function __construct()
  {
   parent::__construct();
   $this->load->database();
  }

  function entry()
  {
   $this->no = '';
   $this->id = $_POST['txtId'];
   $this->pw = $_POST['txtPw'];
   $this->email = $_POST['txtEmail'];
   $this->date = date("Y-m-d H:i:s",time());
   
   $this->db->insert('member', $this);
  }
 }
?>

* 컨트롤러 : login.php
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 class Login extends CI_Controller
 {
  public function __construct()
  {
   parent::__construct();
  } 
  
  public function index()
  {
   $this->load->view('index_view');
  }
  
  public function entry_view()
  {
   $this->load->view('entry_view');
  }
  
  public function process_login()
  {
   $this->load->model('member_model'); 
                 $this->member_model->login();
                 $this->load->view('member_view');
  }
  
  public function process_entry()
  {
   $this->load->model('member_model');
   $this->member_model->entry();
   $this->load->view('index_view');    
  }
 }
?>
* 뷰 : index_view.php
<html>
<head>
<title>L O G I N</title>
<script>
 function evtLogin()
 {
  var f = document.loginForm;
  if((f.txtid.value == "") || (f.txtpw.value = ""))
  {
   alert('다시 확인 해 주세요'); 
  }
  else
  {
   location.href = './process_login';
   f.submit();
  }
  
 }
 
 function evtEntry()
 {
  location.href = './Login/entry_view';
 }
</script>
</head>
<body align = 'center'>
<form name = 'loginForm' method = 'post'>
<table align = 'center' height = '100px' cellpacing = '0' cellpading = '0' border = '1'>
 <tr align = 'center'>
  <td colspan = '2'><b>LOGIN</b></td>
 </tr>
 <tr align = 'center'>
  <td>I   D : </td>
  <td><input type = 'text' size = '15' name = 'txtid' /></td>
 </tr>
 <tr align = 'center'>
  <td>P W : </td>
  <td><input type = 'password' size = '15' name = 'txtpw' /></td>
 </tr>
 <tr align = 'center'>
  <td colspan = '2'>
   <input type = 'button' name = 'btnSubmit' value = 'Login' onclick = 'evtLogin()' />
   <input type = 'button' name = 'btnEntry' value = 'Entry' onclick = 'evtEntry()' />
  </td>
 </tr>
</table>
</form>
</body>
</html>
* 뷰 : entry_view.php
<html>
<head>
<title>E N T R Y</title>
<script>
 function evtDataChk()
 {
  var f = document.entryForm;
  if((f.txtId.value == "") || (f.txtPw.value == "") || (f.txtPw_re.value == "") || (f.txtEmail.value == ""))
  {
   alert('빈칸을 모두 입력하세요');
  }
  else if(f.txtPw.value != f.txtPw_re.value)
  {
   alert('비밀번호가 다릅니다');
  }
  else
  {
   alert('회원 가입 중');
   f.submit();
  }
 }
 
 function evtBack()
 {
  location.href = './Login/index';
 }
</script>
</head>
<body align = 'center'>
<form name = 'entryForm' method = 'post' action = './process_entry'>
<table align = 'center' height = '100px' cellpacing = '0' cellpading = '0' border = '1'>
 <tr align = 'center'>
  <td colspan = '2'><b>ENTRY</b></td>
 </tr>
 <tr align = 'center'>
  <td>I   D : </td>
  <td><input type = 'text' size = '15' name = 'txtId' /></td>
 </tr>
 <tr align = 'center'>
  <td>P W : </td>
  <td><input type = 'password' size = '15' name = 'txtPw' /></td>
 </tr>
 <tr align = 'center'>
  <td>P W : </td>
  <td><input type = 'password' size = '15' name = 'txtPw_re' /></td>
 </tr>
 <tr align = 'center'>
  <td>E-Mail : </td>
  <td><input type = 'text' size = '15' name = 'txtEmail' /></td>
 </tr>
 <tr align = 'center'>
  <td colspan = '2'>
   <input type = 'button' name = 'btnSubmit' value = 'Entry' onclick = 'evtDataChk()' />
   <input type = 'button' name = 'btnBack' value = 'Back' onclick = 'evtBack()' />
  </td>
 </tr>
</table>
</form>
</body>
</html>

첨부파일 121120_Page.zip (431.1 KB)
 다음글 form submit 관련? (5)
 이전글 head, left or right, footer 등 ... (6)

댓글

한대승(불의회상) / 2012/11/21 10:45:14 / 추천 0
./ 로 시작하는 주소를 / 로 시작하도록 바꿔 보세요.

ex>
location.href = '/Login/index'; 


헛발이 / 2012/11/21 10:51:35 / 추천 0
한발 늦었당~
일단은 몇가지를 적어 놓을께요...

1. Path에 관해서는 자신이 직접 몸으로 느껴야 해요...
./ 이렇게 하면 어떻게 되는지..
../ 이렇게 하면 어떻게 되는지..
/ 이렇게 하면 어떻게 되는지..
<?php echo base_url()?>/blog 이렇게 하면 어떻게 되는지..
<?php echo base_url()?>../blog 이렇게 하면 어떻게 되는지..
여러각도로 테스트 해 보면서 직접 느껴야 할듯 싶습니다...

2. 위소스를 보면서 폼검증에 관한 것인데요...
자바스크립트로 폼검증 하는것은 무의미 하다고 생각이 됩니다.
스크립트를 건너띄고 처리될 가능성이 있거든요...
폼을 검증하는것은 코드이그나이터에서 지원되는 기능입니다.
메뉴얼에서 폼검증 라이브러리를 찾아 보시기 바랍니다..
http://cikorea.net/user_guide_2.1.0/libraries/form_validation.html

3. 강좌게시판에 로그인 강좌가 있으니 참고..
http://cikorea.net/lecture/view/116/page/1/
꾸숑 / 2013/01/28 20:37:14 / 추천 0
헛발이//
감사합니다.
게시판 제작중인데... 링크들을
상대링크로 잡다보니 제대로 되었다 안되었다 해서 머리 터질라 했는데
헛발이님 글 읽고 차분하게 해보니 깨끗하게 정리 되었네요...

base_url() 함수를 아래 처럼 일괄적으로 사용하니 정확하네요....
<a href=<?=base_url()?>/board/edit/num/<?=$num?>/>수정</a>
redirect(base_url("board"));

그리고 참고로.. .htaccess 를 아래 처럼 해서 사용했습니다.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

코드이그나이트 매뉴얼 째려본지 2주일 ...
이제 겨우 게시판 읽기, 쓰기, 보기, 삭제, 제작 되었네요..

2주일 투자한 보람은 있는것인지 아직도 확신이 없습니다.
일단 시작했으니 마무리 하자는 마음인데...