본문 바로가기

프로그래밍/Framewrok

Zend Framework 설치하기(구버전 0.8.0)

APM등이 설치되어 있어야 합니다
아래의 폴더명은 제가 정의한 것이며 zend framework 메뉴얼에 보시면 비슷한 패턴으로 폴더를 지정하라는 내용이 있습니다.

~/_app
      /controllers
      /models
      /views
~/_lib
~/document_root  <- 이 폴더를 아파치에서 DocumentRoot 로 잡아주셔야 합니다

이방식은 Zend에서 권장하는 방식이며 외부에서 라이브러리폴더나 로직파일들에 대한 직접적인 접근을 배제할수 있습니다.


 

  1. http://framework.zend.com/download/stable 에서 소스를 다운 받습니다.
  2. 압축을 풀어보시면 library폴더가 있고 그안에는 Zend.php , Zend폴더가 있습니다. 이것을 ~/_lib에 복사를 하십시오.
  3. document_root 폴더에 .htaccess 파일을 만들고

    RewriteEngine on
    RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php

    이 내용을 적습니다.
  4. document_root에 index.php파일을 만들고 아래의 내용을 적습니다.

    <?php
    define(MODELS_PATH, '../_app/models/', true);
    define(ZEND_PATH, '../_lib', true);
    define(CONTROL_PATH, '../_app/controllers', true);
    define(FRONT_PATH, 'Zend/Controller/Front.php', true);

    set_include_path(ZEND_PATH);
    require_once FRONT_PATH;
    Zend_Controller_Front::run(CONTROL_PATH);

    echo '<br>스크립트 종료';
    ?>
  5. _app/controllers 폴더에 indexController.php, testController.php 를 만듭니다.

    indexController.php
    <?php
    require_once 'Zend/Controller/Action.php';
    set_include_path(MODELS_PATH);
    class IndexController extends Zend_Controller_Action {
     public function indexAction() {
      echo 'Hello! World.';
    }

    public function noRouteAction() {
      $this->_redirect('/');
     }
    public function hiAction() {
      echo 'hihihihihi~~~~~~~~~~~~~~~~<br>';
    }
    }
    ?>

    testController.php
    <?php
    require_once 'Zend/Controller/Action.php';
    set_include_path(MODELS_PATH);
    class TestController extends Zend_Controller_Action {
     public function indexAction() {
      echo 'TestController (으)로부터 안녕하세요';
     }
     public function noRouteAction() {
      $this->_redirect('/');
     }
     public function hiAction() {
      echo 'hihihihihi';
     }
    }
    ?>

여기까지 완료되었다면 로컬에서 한다고 가정하고
http://localhost/
http://localhost/index/hi
http://localhost/test
http://localhost/test/hi

해보세요...

여기까지가 Zend Framework의 시작입니다..