문서의 이전 판입니다!
개요
설치
설정
DATABASE 설정
database.php 파일을 설정합니다.
application\config 폴더 안에 있습니다.
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'bearcho';
$db['default']['password'] = 'password';
$db['default']['database'] = 'bearchodb';
$db['default']['dbdriver'] = 'mysql';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
AUTOLOAD 설정
autoload.php 파일은 application\config 있습니다.
$autoload['libraries'] = array() 를 $autoload['libraries'] = array('database') 로 바꿔 줍니다.
위와 같이 설정을 하게 되면 페이지 마다 db connection을 할 필요가 없이 자동으로 연결이 됩니다.
CONFIG 설정
config.php 파일은 application\config 있습니다.
$config['index_page'] = 'index.php' 를 $config['index_page'] = 로 바꾸어 줍니다.
* 위 index_page 설정은 controller가 페이지 이동할 때도 컨트롤러 앞에 자동으로 index.php 페이지를 붙여 준다는 것입니다.
* 주소창에 index.php 항상보이면 보기 안좋기 때문에 뺍니다. 대신 .htaccess로 index.php 를 주소창에 보이지 않지만 가장 먼저 접근 하는 페이지로 설정 할 겁니다.
===== INDEX 설정 =====
* index.php 파일은 웹서버 가장 상위에 있습니다.
* INDEX 파일은 CodeIgniter의 동작 중 가장 기초인 routing을 합니다.
* $routing['controller'] =
를 $routing['controller'] = 'blog' 로 변경합니다.
.htaccess 설정
.htaccess 파일을 상위에 생성 해줍니다.
rewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
위 내용을 쓰고 저장합니다. 위 설정은 주소로 접을 했을 때 가장 먼저 index.php 파일을 읽는 다는 것이고 주소창에는 index.php가 보이지 않습니다.
config 설정과 .htaccess 설정은 주소창을 깔끔하게 보이기 위한 것이지 꼭 필요한 설정은 아닙니다.
활용
테스트에서 DB는 Mysql을 사용했고 test란 테이블을 하나 만들었습니다. 테이블에 Id int(11)autoincrease, title varchar(255), contents text란 컬럼이있습니다.
단계1
class Blog extends CI_Controller {
public function index()
{
echo "hello codeigniter";
}
}
단계2