📘 Day 3 (2025.09.16.TUE) - CodeIgniter 4 설치, 정적 페이지 설정
📥 CI4 다운로드
c:/xampp/htdocs/CI4 폴더에 압축 풀기
⚙️ Apache 설정 (httpd.conf)
경로: C:\xampp\apache\conf\httpd.conf
DocumentRoot "C:/xampp/htdocs/CI4/public"
<Directory "C:/xampp/htdocs/CI4/public">
수정 후 Apache 재시작(xampp control panel)
⚙️ PHP 설정 (php.ini)
경로: C:\xampp\php\php.ini
extension=intl 앞의 주석 제거
extension=curl
extension=mbstring
extension=json
📁 MVC 설명
📝 정적 페이지 설정
app/Controllers/Pages.php 생성
<?php
namespace App\Controllers;
class Pages extends BaseController
{
public function index()
{
return view('welcome_message');
}
public function view($page = 'home')
{
// ...
}
}
📄 뷰 파일 작성
app/Views/templates/header.php
<!doctype html>
<html>
<head>
<title>CodeIgniter Tutorial</title>
</head>
<body>
<h1><?= esc($title) ?></h1>
app/Views/templates/footer.php
<em>© 2021</em>
</body>
</html>
🧠 컨트롤러 로직 추가
app/Views/pages/ 안에 home.php과 about.php 생성
app/Controllers/Pages.php에 아래 코드 추가
public function view($page = 'home')
{
if (! is_file(APPPATH . 'Views/pages/' . $page . '.php')) {
throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
}
$data['title'] = ucfirst($page);
return view('templates/header', $data)
. view('pages/' . $page)
. view('templates/footer');
}
🌐 라우팅 설정
app/Config/Routes.php
$routes->get('pages', 'Pages::index');
$routes->get('(:segment)', 'Pages::view/$1');
localhost/pages → index 실행됨
🚀 앱 실행
http://localhost/home 접속
http://localhost/about 접속