728x90

composer가 설치되어 있다는 가정 하에 시작한다.


먼저 작업 디렉토리를 만들어 해당 디렉토리로 이동한다.


propel 2를 composer에 추가한다.


글 작성 시점 현재 stabled 버전이 없으므로 아래와 같이 추가한다.


$ composer require propel/propel:~2.0@dev


다음으로 CI를 추가한다.


$ composer require codeigniter/framework


propel이 설치되면서 생성 된 vendor/bin 디렉토리로 이동하여 propel 초기화를 실행한다.


$ cd vendor/bin

$ ./propel init


아래 연두색 부분을 자신의 설정에 맞게 입력한다.




Please pick your favorite database management system:
[mysql ] MySQL
[sqlite] SQLite
[pgsql ] PostgreSQL
[oracle] Oracle
[sqlsrv] MSSQL (via pdo-sqlsrv)
[mssql ] MSSQL (via pdo-mssql)
> {DB종류}
Please enter your database host [localhost]: {DB 호스트}
Please enter your database port [3306]: {포트}
Please enter your database name: {DB명}
Please enter your database user [root]: {계정}
Please enter your database password: {패스워드}
Which charset would you like to use? [utf8]: {CHARSET}
Connected to sql server successful!
The initial step in every Propel project is the "build". During build time, a developer describes the structure of the datamodel in a XML file called the "schema".
From this schema, Propel generates PHP classes, called "model classes", made of object-oriented PHP code optimized for a given RDMBS. The model classes are the primary interface to find and manipulate data in the database in Propel.
The XML schema can also be used to generate SQL code to setup your database. Alternatively, you can generate the schema from an existing database.
Do you have an existing database you want to use with propel? [no]: {기존 데이터베이스 사용 여부}
Where do you want to store your schema.xml? [/home/webdev/workspace/orm/vendor/bin]: {schema.xml 파일을 생성할 위치 지정}
Where do you want propel to save the generated php models? [/home/webdev/workspace/orm/vendor/bin]: {Propel이 자동 생성 할 ORM 클래스들의 위치 지정}
Which namespace should the generated php models use?: {\네임스페이스명}


composer에서 autoload 할 수 있도록 설정을 추가 해 준다.


"autoload": {
"psr-4": {
"{네임스페이스명}\\": "{위에서 설정한 model classes 디렉토리}/"
},
"files": [
"vendor/bin/generated-conf/config.php"
]
}


composer에 autoload를 반영 해 준다.


$ cd ../../
$ composer dump-autoload


codeigniter에서 application과 index.php를 꺼낸다.


$ mv vendor/codeigniter/framework/application ./
$ mv vendor/codeigniter/framework/index.php ./


index.php에서 system 경로를 수정 해 준다.



$system_path = 'vendor/codeigniter/framework/system';


application/config/config.php 에서 composer autoload 경로를 잡아준다.


$config['composer_autoload'] = "vendor/autoload.php";



위에서 namespace 부분을 비워두면 use 없이 class를 바로 사용할 수 있다.


하지만 DB의 테이블명과 CI의 controller 명이 일치하는 경우, 


propel에서 자동 생성되는 model class 명도 동일하게 생성되기 때문에 class를 찾지 못하는 문제가 발생할 수 있다.


phpstorm의 경우 alt + insert를 통해 지정되지 않은 클래스의 namespace use 코드를 바로 추가할 수 있으므로 가급적 지정하는 편이 좋겠다.




※ special thanks to KMK




Propel: http://propelorm.org/

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기