sfGuardPluginをテスト
sfGuardPluginをテスト
symfonyのalphaバージョン入れただけではつまんないので、sfGuardPluginを突っ込んでみます。
sfGuardPluginは、symfonyを使ったユーザ、グループ、権限管理を提供してくれる便利なモジュール。まだ未実装な機能もあったりで、完成とは言い難いですが、これを足場にしてシステム管理用アプリを作るのも良いでしょう。
前回同様、PHPIDEベースで進めていきます。
External Toolsつくるのがちょっと面倒になったので、Antにチェンジします。 以下のようなコードを、PHPIDEのsymfonyプロジェクトのルートディレクトリに、build.xmlという名前で保存します。
<?xml version="1.0"?>
<!-- ======================================================================
2006/07/20 2:48:05
Symfony Project Builder
Symfony Command Helper
Administrator
====================================================================== -->
<project name="Symfony Project Builder" default="default">
<description>
Symfony Command Helper
</description>
<!-- =================================
target: default
================================= -->
<target name="default" depends="depends" description="--> Symfony Command Helper">
<echo>Symfony コマンド</echo>
<!-- executable="PHPのインストールディレクトリ\php" -->
<exec executable="D:\php52\php" resultproperty="command_help">
<!-- line="作成したプロジェクトの相対パス/symfony -T" -->
<arg line="project/symfony -T"/>
</exec>
<input message="コマンドを入力してください" addproperty="sf_command" defaultvalue="-T"/>
<!-- executable="同じくPHPのインストールディレクトリ\php" -->
<exec executable="D:\php52\php">
<!-- line="こちらも同じく相対パス/symfony -T" -->
<arg line="project/symfony ${sf_command}"/>
</exec>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: depends
- - - - - - - - - - - - - - - - - -->
<target name="depends">
</target>
</project>
保存したbuild.xmlを右クリックし、Run As => Ant Build...を選択
設定が終わったら、Runを実行
OKを押すと、adminがappディレクトリに追加されます
次にプラグインをインストールします。Run As => Ant Buildを選択
symfony plugin-install http://plugins.symfony-project.com/sfGuardPlugin を実行
......あれ!ここでPEARが必要に…。でもPHP5.2.0は標準でPEARをバンドルしてません。
ということで、PHP5.2.0のインストールディレクトリで、go-pear.batを実行してはみたものの…エラー続きでインストールできず!こんなところにPHP5.2.0の罠が…
どうやらcvsでコミットしてるようなので、ここからgo-pear.pharファイルをダウンロードして、phpインストールディレクトリ/PEAR内にあるgo-pear.pharを上書きする。
そのあと、go-pear.batを実行。はじめにlocalを選択し、その後はひたすらEnter
これでいけるようです。5.2.1が来るのもすぐかも…PHPのX.0シリーズはいつも短命ですね。
気を取り直してもう一度。以下のコマンドを実行していきます
plugin-install http://plugins.symfony-project.com/sfGuardPlugin
symfonyプロジェクトのデータベース設定(この例ではmysql)
#config/databases.yml
all:
propel:
class: sfPropelDatabase
param:
dsn: mysql://root:@localhost/dbname
# DB名://ユーザ名:パスワード@DBサーバアドレス/DB名
;config/propel.ini propel.database = mysql propel.database.createUrl = mysql://localhost/ propel.database.url = mysql://root:@localhost/dbname
DBの設定が終わったら、Ant Buildで次のコマンドを実行
propel-build-all
作成されたテーブルに、ユーザや権限の情報を追加します。Ant Buildで以下を実行
propel-load-data admin
propel-load-data init-appで作った名となります。
symfonyプロジェクト/apps/作成したapp名/config/settings.ymlを、以下のように編集し、sfGuardモジュールをアクティブにし、sfGuardAuthモジュールを使い認証をさせるようにします。
all:
.actions:
login_module: sfGuardAuth
login_action: signin
secure_module: sfGuardAuth
secure_action: secure
.settings:
activated_modules: [default, sfGuardAuth, sfGuardGroup, sfGuardUser, sfGuardPermission, sfGuardModule]
routing.ymlを編集します。default_symfony:の前あたりに以下を追加します。
sf_guard_signin:
url: /login
param: { module: sfGuardAuth, action: signin }
sf_guard_signout:
url: /logout
param: { module: sfGuardAuth, action: signout }
sf_guard_password:
url: /request_password
param: { module: sfGuardAuth, action: password }
factories.yml内で、userに使用するクラスをsfGuardSecurityUserに変更。 factories.ymlは、各app内のconfigディレクトリよりも、projectのconfig内にfactories.ymlをコピって来て、 それを編集する方がいいでしょう。全appにfactories.ymlの設定が反映されます。
all:
user:
class: sfGuardSecurityUser
最後にsecurity.ymlのis_secureをonにして、完了。
Ant Buildで以下を実行し、キャッシュをクリアします。
cc
以上が終わったら、http://symfonyサイトURL/admin_dev.php/login にアクセスしてみましょう。 ID:admin Pass:admin で認証できます。
認証が終わると、TOPページが表示されるので、User、Group、Module、Permissionと、各モジュールに アクセスしてみましょう。
- http://symfonyサイトURL/admin_dev.php/sfGuardUser
- http://symfonyサイトURL/admin_dev.php/sfGuardGroup
- http://symfonyサイトURL/admin_dev.php/sfGuardModule
- http://symfonyサイトURL/admin_dev.php/sfGuardPermission
- http://symfonyサイトURL/admin_dev.php/logout
どうやらsfGuardGroupのテンプレ_permissions.phpが足りないようなので、 svnからダウンロードしてきます。
これで一通りのことができるようになりました。(required_passwordはまだみたいなので、各自実装)
Posted by Imlktak at 2006年11月04日 21:48 | TrackBack