//view 페이지//
<a type="button" id="feelBtn" class="btn btn-primary" data-target="#feelModal" data-toggle="modal" data-backdrop="true" data-achid="2" data-brd="b-c-2" data-remote=''>
button </a>
<div class="modal" id="feelModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
<div class="modal-dialog modal-wide">
<div class="modal-content">
<div class="modal-body">
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#feelBtn").click(function(){
var achid= $(this).data("achid");
var brdkey= $(this).data("brd");
$.ajax({
url : "www.abc.com/url/posturl",
type : 'POST',
data : {ach_id: achid,
brd_key: brdkey,
csrf_test_name: cb_csrf_hash
},
dataType: 'json',
success: function(data){
$(this).data("remote",data);
}
});
})
})
</script>
//controller//
public function posturl()
{
$brd_key = $this->input->post('ach_id');
$ach_id = (int) $this->input->post('brd_key');
$this ->load->model('Url_model');
$post_id = $this->Url_model->posturl($ach_id);
$result = post_url($brd_key, $post_id);
exit(json_encode($result));
}
//model//
class Url_model extends CB_Model
{
public $_table = 'post';
public $primary_key = 'post_id';
public $allow_order = array('post_num, post_reply', 'post_datetime desc', 'post_datetime asc', 'post_hit desc', 'post_hit asc', 'post_comment_count desc', 'post_comment_count asc', 'post_comment_updated_datetime desc', 'post_comment_updated_datetime asc', 'post_like desc', 'post_like asc', 'post_id desc');
function __construct()
{
parent::__construct();
}
public function posturl($ach_id=''){
$user_id = $this->member->is_member();
$this->db->select('post_id');
$this->db->from($this->_table);
$this->db->where('mem_id',$user_id);
$this->db->where('ach_id',$ach_id);
$qry= $this->db->get();
$result= $qry->row();
return $result;
}
}
//button을 클릭했을 때 controller로 data인 achid와 brdkey값이 안넘어 가는 것 같습니다. 도대체 이유를 모르겠어요 ㅠㅠ//
//제가 지향 하는 결과는 controller에서 출력되는 $result값이 www.abc.com/post/3 이라는 값이 view에 전달되어 modal의 data-remote 값이 이 결과 값이 되게 하여 modal 창을 띄우는 것입니다.//
@한대승(불의회상) 답변 감사합니다. 제가 알기로 <a 태그의 id="feelbtn" data-achid ="2" data-brd="b-c-2">라고 되어있을때,
$("#feelBtn").click(function(){ var achid= $(this).data("achid"); var brdkey= $(this).data("brd");이 부분에서 achid = 2값이 불러오는게 아닌가요?
제 짧은 생각에는 controller 안의 이 부분이 뭔가 문제가 있는 것 같습니다.
$brd_key = $this->input->post('ach_id');
$ach_id = (int) $this->input->post('brd_key');
그 이유는 firebug로 보면 post 값이
|
Parametersapplication/x-www-form-urlencodedDo not sort
|
|
| ach_id | 2 |
| brd_key | b-c-2 |
| csrf_test_name | 5736893543449721c917062d04bad65d |
|
Source
|
|
ach_id=2&brd_key=b-c-2&csrf_test_name=5736893543449721c917062d04bad65d |
다음 과 같이 나오기 때문입니다.
@trace 그렇군요. 소스코드가 다 보이지 않아 그 부분을 간과 한 것 같습니다.
firebug로 값을 모니터링 하실 수 있다면, $this->output->enable_profiler() 가 도움이 될 것 같습니다.
제 기억이 맞다면 var_dump($ach_id); 찍어보시면 예상하지 못한 값이 들어가 계실겁니다. 스트링 값을 넘겼는데 int 캐스팅 넣으면 0 으로 치환합니다.
그리고 php의 오토 캐스팅에 의해서 0 은 false 이나 null 으로 처리해서, 만일 해당 인자값이 필수 라면 원치 않는 결과값이 나오게 됩니다.
@kaido 좋은 아침입니다.! 답변 감사합니다.
제 짧은 지식으로 (int)가 string으로 온 숫자를 int 숫자로 바꾸는 기능이 있는 것 아닌가요?
해당 인자값이 필수입니다
아 저도 헷깔렸네요 ㅋㅋㅋ
var_dump($brd);
찍어보세요. $brd 를 인트형으로 변환 시키고 계십니다.
또한 오토캐스팅에 의해서 int 형인지 string 형인지는 자동으로 구분지어 주기도 합니다.
문제는 강제로 형변환을 할 경우 타입이 맞지 않으면 0 으로 바꿔서 넣어줍니다.
이부분은 원인 파트이고...
echo $str = $this->db->last_query();
해보시면 문제가 나올거라 보입니다.
@kaido 아 죄송합니다 제가 글을 잘못 작성하여 혼란시켜드렸습니다.
//위글에는//
$brd_key = $this->input->post('ach_id');
$ach_id = (int) $this->input->post('brd_key');
// 이렇게 되어있는데//
$brd_key = $this->input->post('brd_key');
$ach_id = (int) $this->input->post('ach_id');
//로 원래는 되어있습니다.//
밑의 구문은 퇴근 후 집에가서 한번 해보겠습니다 감사합니다.!
@한대승(불의회상) 아 그렇군요! 전 연산하기 위해서 문자를 숫자로 바꿔야 되는줄 알았습니다. ㅠ
하드웨어 하다가 용돈좀 벌어보겠다고 웹서비스 개인적으로 구성중인데 힘드네요 ㅎㅎ