3.3.3 고급설치(Advanced Installation)
간혹 하나의 파일 시스템에서 여러 다른 곳에 CakePHP 디렉토리를 사용하는 경우가 있을 겁니다. 공유해서 사용하는 호트스라 제한이 있는 경우, 또는 여러개의 프로젝트에서 같은 Cake 라이브러리를 공유하고 싶은 경우가 있습니다. 이 섹션에서는 어떻게 CakePHP 디렉토를 공유하여 사용할 것인지에 대해 설명합니다.
첫 째로, CakePHP 프로그램은 크게 세개로 나뉘어 집니다.:
- 코어 CakePHP 라이브러이인 /cake 가 있습니다.
- 여러분의 응용 프로그램인 /app 가 있습니다.
- 응용 프로그램의 웹 루트인 /app/webroot 가 있습니다.
webroot 이외의 디렉토리는 파일 시트템의 어디든 두고 사용 할 수 있습니다. webroot 디렉토리는 여러분의 웹 서버를 통해 접근할 수 있어야하기 때문에 웹 루트 디렉토리 이하에 있어야 합니다. 그리고 app 폴더 안의 webroot 폴더도 app 폴더 밖으로 놓을 수 있습니다.
여러분의 Cake 를 설치하고 /app/webroot/index.php 설정의 일부 내용을 변경해 주어야 합니다. 다음 세개의 상수 변수를 수정 할 필요가 있습니다.: ROOT 와 APP_DIR, CAKE_CORE_INCLUDE_PATH.
- ROOT 에 응용 프로그램 app 폴더가 들어있는 경로로 설정합니다.
- APP_DIR 에 app 폴더 경로를 설정합니다.
- CAKE_CORE_INCLUDE_PATH 에CakePHP 라이브러리 폴더 경로를 설정합니다.
예제를 통해 고급설치를 연습해 봅시다. 다음과 같이 CakePHP를 설정해 보았습니다.:
- CakePHP 코어 라이브러리를 /usr/lib/cake 에 두었습니다.
- 저의 응용 프로그램인 webroot 디렉토리를 /var/www/mysite/ 로 만들었습니다.
- 저의 응용 프로그램인 app 디렉토리를 /home/me/mysite 로 만들어 저장하였습니다.
주어진 설치를 위해, 다음과 같이 webroot/index.php 파일(저의 경우 예제로 /var/www/mysite/index.php 파일입니다.) 을 수정해 주어야 합니다.:
// /app/webroot/index.php (이 파일을 수정해야 합니다. 저의 경우 /var/www/mysite/index.php 파일 입니다.)
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'me');
}
if (!defined('APP_DIR')) {
define ('APP_DIR', 'mysite');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', DS.'usr'.DS.'lib'.DS.'cake');
}
// /app/webroot/index.php (이 파일을 수정해야 합니다. 저의 경우 /var/www/mysite/index.php 파일 입니다.)if (!defined('ROOT')) {define('ROOT', DS.'home'.DS.'me');}if (!defined('APP_DIR')) {define ('APP_DIR', 'mysite');}if (!defined('CAKE_CORE_INCLUDE_PATH')) {define('CAKE_CORE_INCLUDE_PATH', DS.'usr'.DS.'lib'.DS.'cake');}
파일 경로를 기술 할때 슬래시 기호 보다 상수 DS 를 사용하는 것이 좋습니다. 이렇게하면 모든 파일에서 잘못된 기호의 사용으로 파일을 찾을 수 없게 되는 것을 예방 할 수 있으며 더욱 간편하게 코드를 작성 할 수 있습니다.
3.3.3.1 Additional Class Paths
It’s occasionally useful to be able to share MVC classes between applications on the same system. If you want the same controller in both applications, you can use CakePHP’s bootstrap.php to bring these additional classes into view.
In bootstrap.php, define some specially-named variables to make CakePHP aware of other places to look for MVC classes:
$viewPaths = array(); $controllerPaths = array(); $modelPaths = array(); $helperPaths = array(); $componentPaths = array(); $behaviorPaths = array();
$viewPaths = array();$controllerPaths = array();$modelPaths = array();$helperPaths = array();$componentPaths = array();$behaviorPaths = array();
Each of these special variables can be set to an array of absolute filesystem paths where extra classes can be found when requested. Make sure that each path specified includes a trailing slash.
