| 제목 | 검색파라미터 구하기 | ||
|---|---|---|---|
| 글쓴이 | 마냐 | 작성시각 | 2009/08/06 22:59:18 |
|
|
|||
// 검색 파라미터
class search_seg {
private $seg;
public function __construct($n=3) {
$CI =& get_instance();
$this->seg = array_map(array('search_seg','escape'), $CI->uri->uri_to_assoc($n));
}
private function escape($v) {
return mysql_real_escape_string($v);
}
public function get_seg($seg_key) {
if (isset($this->seg[$seg_key]))
return $this->seg[$seg_key];
return false;
}
public function get_qstr() {
if ($this->seg) {
$CI =& get_instance();
return '/'.$CI->uri->assoc_to_uri($this->seg);
}
}
}
// replace
function qstr_rep($qstr, $key, $val='') {
$keys = explode(',', $key);
foreach ($keys as $row)
$srh[] = '(/'.$row.'/[a-z0-9_-]+)';
$val = ($val) ? '/'.$key.'/'.$val : '';
return preg_replace($srh, $val, $qstr);
}
// 사용법
// EX: http//.../board/temp/page/1/wid/44/stx/text
$seg = new search_seg(3); // 오프셋 설정 : 3번째 부터
$page = $seg->get_seg('page');
$wid = $seg->get_seg('wid');
$stx = $seg->get_seg('sst');
...
$qstr = $seg->get_qstr(); // query_string : /page/1/wid/44/stx/text ...
// 값 변환
$qstr_test1 = qstr_rep($qstr, 'stx', 'val');
// > /page/1/wid/44/stx/val ...
// 값 삭제
$qstr_test2 = qstr_rep($qstr, 'page,stx');
// > /wid/44 ...
오늘 하루 종일 이것만 가지고 씨름했네요. 오후에 올릴려고 보니까 좀 거시기해서 replace 부분도 클래스로 묶어서 따로 $qstr 을 넘겨주지 않도록 해봤는데 객체로 하다보니... $qstr = $seg->get_qstr(); >> /wid/44 ... $seg->replace('wid', '33'); $qstr = $seg->get_qstr(); >> /wid/33 ... 단점이 더 많아!! 결론 : 뻘짓... ㅡ_ 태글과 의견 좀 굽슨굽슨... 그런데 이건 helper로 구분해야 되겠지요? |
|||
| 다음글 | [팁] CI DOC (2) | ||
| 이전글 | [팁] CI 이용시 가변변수 응용예제 (2) | ||
|
변종원(웅파)
/
2009/08/08 08:57:11 /
추천
0
홍홍. 포럼 소스에 적용해야겠습니다. ^^
|
|
터프키드
/
2009/09/10 12:55:20 /
추천
0
좋은팁 감사드립니다!
|