[CI] 환경설정

Grace Goh·2023년 3월 17일
0

PHP

목록 보기
4/19

Codeigniter에서 주로 사용하는 디렉토리

/application # (이하 app)
	/config
    /controllers
    /helpers # optional, 라이브러리 관련
    /models
    /views

# app/config/config.php

$config['base_url'] = '/';
// $config['base_url'] = 'http://localhost/';

$config['index_page'] = '';
// url 경로에서 index.php를 생략했다.

$config['uri_protocol']	= 'REQUEST_URI';
// uri_protocol로 이상이 있으면 $_SERVER['QUERY_STRING']로 바꿔도 된다.

database

# app/config/database.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root',
	'password' => '',
	'database' => 'mydb',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE
);

routes.php

어느 페이지로 이동하고 어떤 처리를 하는지 등을 설정한다.

# app/config/routes.php 

$route['default_controller'] = 'welcome';
// Welcome controller가 default로 설정되어 있다.
.
.
.
// uri에 ['괄호']를 입력하면 ""로 이동한다.
$route['board'] = "board/index";
$route['board/create'] = "board/create";

controller

Welcome controller를 복사해서 Board Controller를 만든다.

# Controller/board.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Board extends CI_Controller {

    public function index() {

        $this->load->view('board/list');
    }
}

.htaccess

root 폴더에 위 파일을 만들고 다음 내용을 적는다.

# .htaccess 

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

# board/create.php

<form name="board_form" action="/board/store" method="post">
	게시판 글쓰기 화면
	<table board="1">
        <tr>
            <th>제목</th>
            <td>
                <input type="text" name="title" value="" placeholder="" />
            </td>
        </tr>
        <tr>
            <th>내용</th>
            <td>
                <textarea name="contents" rows="8" placeholder=""></textarea>
            </td>
        </tr>
        <tr>
            // 2개를 합친다.
            <th colspan="2">
                <input type="submit" value="저장" />
            </th>           
        </tr>
    </table>
</form>

store는 data를 DB로 저장하는 단계. DB 관련 처리는 models에서 한다.


출처 https://www.youtube.com/watch?v=TXHWW4dvFzo

profile
Español, Inglés, Coreano y Python

0개의 댓글