티스토리 뷰
CI에서는 url을 변경하는 파일이 있는데요, 위치는 application/routes.php 입니다.
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
class Main extends CI_Controller{
public function index(){
$this->load->view('index');
}
public function main(id){
$this->load->view('main');
}
}
이 부분에서 default_controller는 도메인/프로젝트파일명으로 접속했을 때 자동으로 연결해 줄 컨트롤러를 의미합니다.
저는 메인이라는 컨트롤러를 지정해주었기 때문에 application/controllers/main.php의 index 함수가 실행이 되어 application/views/index.php 파일이 로드됩니다.
그렇다면 원하는 url로 변경해주려면 어떻게 해야 할까요?
예를 들어, Main controller의 main이라는 함수에 접근하기 위해서는 도메인/프로젝트파일명/index.php/main/main/id로 접속해야 합니다. 하지만 컨트롤러명과 함수명이 중복되기 때문에 쓸데없이 url 주소가 길어집니다. 아래와 같이 추가하시면 됩니다.
$route['main/(:num)'] = 'main/main/$1';
main 뒤에 숫자가 오면 "main/main/해당 숫자"로 연결해줘, 하고 설정해주는 것입니다.
도메인/프로젝트파일명/index.php/main/main/id => 도메인/프로젝트파일명/index.php/main/id
만약 파라미터가 2개라면 이렇게 설정할 수 있겠죠.
$route['main/(:num)/(:num)'] = 'main/main/$1/$2';
만약 도메인/프로젝트파일명/index.php/main/main으로 접속 시에도 도메인/프로젝트파일명/index.php/main/index 파일을 보여주고 싶다면 이렇게 추가하면 됩니다.
class Main extends CI_Controller{
public function index(){
$this->load->view('index');
}
public function main(id,cnt){
$this->load->view('main');
}
}
$route['main/main'] = 'main/index';
도메인/프로젝트파일명/index.php/main/main => 도메인/프로젝트파일명/index.php/main/index
간단하게 URL routing을 해보았습니다.
'Codeigniter' 카테고리의 다른 글
| [Codeigniter] alert helper 추가하기 (0) | 2022.04.16 |
|---|---|
| [Codeigniter] CI3 MongoDB 연동 on windows (0) | 2022.04.15 |
- Total
- Today
- Yesterday
- curl ssl 인증서
- php mongodb
- 카톡 링크 공유 썸네일
- php composer 설치
- JS session
- 자바스크립트 세션
- react restful API
- 자바스크립트
- fetch post 데이터 전송
- php 게시판
- HTML
- php mysql 랜덤 숫자
- http 접속 시 https 리다이렉션
- AJAX
- JS url 파라미터
- react fetch
- JS 시계 기능
- curl.cainfo 에러
- php composer
- curl.cainfo
- curl ssl 인증서 다운로드
- JavaScript
- input placeholder
- curl.cainfo 적용
- fetch get post 전송
- html input
- 자바스크립트 url 파라미터 추출
- 링크 공유 시 썸네일
- php rand()
- 링크 공유 시 정보 수정
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |