marunomaruno-memo

marunomaruno-memo

Windows に symfony をインストール

2008年12月27日 | PHP
Windows に symfony をインストール
================================================================================

(前提) XAMPP 2.5 は C:xampp ディレクトリーにインストール済み、pear もインストー
ル済

■参考URL

symfony PHP Framework
http://www.symfony-project.org/

Official documentation と Tutorials
http://www.symfony-project.org/doc/
日本語に訳されている部分もあるが、すべてではない。

http://symfony.xrea.jp/1.0/book/index.html (2009-07-05 追記)

■symfonyインストール

まず、チャネルを定義し、そのチャネルを使ってオンラインでインストールする。
インストールした後は、symfony のバージョンを確認する。

---
C:xamppphp>pear channel-discover pear.symfony-project.com
PHP Warning: Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded

C:xamppphp>pear install symfony/symfony
PHP Warning: Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
downloading symfony-1.2.1.tgz ...
Starting to download symfony-1.2.1.tgz (2,689,398 bytes)
..............................................................done: 2,689,398 by
tes
install ok: channel://pear.symfony-project.com/symfony-1.2.1

C:xamppphp>symfony -V
PHP Warning: Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
symfony version 1.2.1 (C:xamppphpPEARsymfony)
---


★ワーニングの対処
---
C:eclipseeclipse_PDTpluginsorg.zend.php.debug.debugger.win32.x86_5.2.14.v200
80602resourcesphp5ZendDebugger.dll

C:xamppphpzendOptimizerlibDebuggerphp-5.2.x
ディレクトリにコピー

すればよさそうだが、ここにはすでに ZendDebugger.dll がある。なぜ出るのだろうか?
とりあえず、ここではワーニングなので、無視する。
---



■symfony プロジェクトの構成

symfonyでは、その web アプリケーションの作成を、
プロジェクト
アプリケーション
モジュール
アクション
という単位で作成する。

プロジェクトは、web アプリケーションの単位、
アプリケーションは、機能の単位(サービスやユースケースの単位)、
モジュールは、一連の画面の流れの単位、
アクションは、画面や、フォームの単位
と考えればよい。

作成手順としては、つぎのように作成する。
(1)プロジェクト用のディレクトリーの作成
(2)プロジェクトの作成
(3)アプリケーションの作成
(4)モジュールの作成
(5)アクションの編集
(6)テンプレートの編集

なお、(1)、(2)は、一度作ればおわりである。また、(2)以降の(3)、(4)を行う symfony
コマンドは、symfony のプロジェクトのディレクトリーをカレントディレクトリーとして
作業する必要がある。



■symfonyプロジェクトの作成

C:xampphtdocs ディレクトリーの下に symfony ディレクトリーをつくり、そこをカレ
ントディレクトリーとして作業する。

プロジェクトの作成は、つぎのコマンドによる。
---
symfony init-project プロジェクト名
---

---
C:xampphtdocssymfony>symfony init-project symfony
PHP Warning: Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
>> dir+ C:xampphtdocssymfonyapps
: (略)
>> chmod 777 C:/xampp/htdocs/symfony/web/uploads/assets
---


■helloworld アプリケーションを作る

アプリケーションの作成は、つぎのコマンドによる。
---
symfony init-app アプリケーション名
---

---
C:xampphtdocssymfony>symfony init-app helloworld
PHP Warning: Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
>> dir+ C:xampphtdocssymfonyapps/helloworldconfig
>> file+ C:xampphtdocssymfonyapps/helloworldconfig/app.yml
: (略)
>> chmod 777 C:/xampp/htdocs/symfony/web/uploads/assets
>> dir+ C:xampphtdocssymfonytest/functional/helloworld

---


■symfony をブラウザーで見てみる

プロジェクトを作るだけではなく、少なくともひとつはアプリケーションを作らないと、
symfony の画面は表示されない。

http://localhost/symfony/web/

つぎのような画面が表示される。()
------------------------------------------------------
 symfony PHP Framework
ok
Symfony Project Created
Congratulations! You have successfully created your symfony project.

Project setup successful
    This project uses the symfony libraries. If you see no image in this page, y
ou may need to configure your web server so that it gains access to the symfony_
data/web/sf/ directory.
This is a temporary page
    This page is part of the symfony default module. It will disappear as soon a
s you define a homepage route in your routing.yml.
What's next

        * Create your data model
        * Customize the layout of the generated templates
        * Learn more from the online documentation

---



■helloworld モジュール作成

モジュールの作成は、つぎのコマンドによる。
---
symfony init-module アプリケーション名 モジュール名
---

---
C:xampphtdocssymfony>symfony init-module helloworld helloworld
PHP Warning:  Zend Debug Server for PHP 5.2.x cannot be found (expected at 'C:x
amppphpzendOptimizerlibDebuggerphp-5.2.xZendDebugger.dll') - try reinstall
ing the Zend Debug Server in Unknown online 0
>> dir+      C:xampphtdocssymfonyappshelloworldmodules/helloworldactions
    : (略)
>> tokens    C:/xampp/htdocs/symfony/apps/he...ello/templates/indexSuccess.php

C:xampphtdocssymfony>
---



■Eclipse でプロジェクトを作る

Eclipse のワークスペースは、C:xampphtdocsworkspace になっているので、プロジェ
クト作成時に [Use default] のチェックをはずして、[Directory] を自分で指定して作
る。

プロジェクト名 helloworld

[Use default] のチェックをはずして、[Directory] を次に指定する。
C:xampphtdocssymfonyapps


■ソースを確認する

symfony は、アーキテクチャーパタンの MVC パターンを基本にしています。
今回作ったモジュールでは、 C (Controller) の部分と、 V (View) の部分に対応した
ソースができます。

C (Controller) の部分は、
modules/モジュール名/actions/actions.class.php
というファイルに、sfActions クラスを継承した「モジュール名Actions」というクラス
としてできます。

V (View) の部分は、
modules/モジュール名/templates/indexSuccess.php
というソースができます。


□MVC モデルの C (Controller) の部分に相当するソース

modules/helloworld/actions/actions.class.php
------------------------------------------------------


/**
 * helloworld actions.
 *
 * @package    symfony
 * @subpackage helloworld
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class helloworldActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->forward('default', 'module');    // (1)
  }
}
------------------------------------------------------



□MVC モデルの V (View) の部分に相当するソース

これは、0 バイトのファイルとして、作られる。

modules/helloworld/templates/indexSuccess.php
------------------------------------------------------
(空ファイル)
------------------------------------------------------




■helloworld モジュールをブラウザーで見る

http://localhost/symfony/web/helloworld_dev.php/helloworld
()

------------------------------------------------------
 symfony PHP Framework
module created
Module "helloworld" created
Congratulations! You have successfully created a symfony module.

This is a temporary page
    This page is part of the symfony default module. It will disappear as soon a
s you override the index action in the new module.
What's next

        * Browse to the apps/helloworld/modules/helloworld/ directory
        * In actions/actions.class.php, edit the executeIndex() method and remov
e the final forward
        * Customize the templates/indexSuccess.php template
        * Learn more from the online documentation
------------------------------------------------------


現在の状態で、上記のように見えるのは、
modules/helloworld/actions/actions.class.php
の (1) の部分があるからである。
これは、このモジュールのデフォルトのテンプレートをに制御を渡す、というもの。

自分でつくるテンプレートをもとにブラウザーに表示する場合は、この行は削除(コメン
トアウト)する。

ネーミングとして、
executeIndex() メソッドの実行後に制御がわたるのは indexSuccess.php
になる。


■Hello, Symfony world! を表示

□modules/helloworld/actions/actions.class.php
------------------------------------------------------


/**
 * helloworld actions.
 *
 * @package    symfony
 * @subpackage helloworld
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class helloworldActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
//    $this->forward('default', 'module');    // (1)
  }
}
------------------------------------------------------



□modules/helloworld/templates/indexSuccess.php
------------------------------------------------------

Hello, Symfony World! 
at 
------------------------------------------------------



以上


最新の画像もっと見る

コメントを投稿