<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sun Limited Mt. &#187; symfony</title>
	<atom:link href="http://www.syuhari.jp/blog/archives/category/symfony/feed" rel="self" type="application/rss+xml" />
	<link>http://www.syuhari.jp/blog</link>
	<description>I love iPhone, CakePHP and WordPress.</description>
	<lastBuildDate>Thu, 22 Jul 2010 02:13:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[symfony] askeet はやめます</title>
		<link>http://www.syuhari.jp/blog/archives/479</link>
		<comments>http://www.syuhari.jp/blog/archives/479#comments</comments>
		<pubDate>Mon, 07 Jul 2008 01:38:52 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[validate]]></category>
		<category><![CDATA[xrea]]></category>
		<category><![CDATA[yml]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=479</guid>
		<description><![CDATA[今日 askeet の6日目をやっていたのですが、askeet はとりあえずやめることにしました。
6日目はバリデーションの実装なのですが、どうも symfony1.1 からバリデーションの実装方法が結構変わっているようです。
validate ディレクトリに yml ファイルでバリデーションを定義してもちっとも有効にならず悩んでいたのですが、下記のような記事を見つけました。
[Think IT] 第3回：フォームフレームワークを使おう！ (1/3)

上記記事によると 1.1 ではフォームフレームワークを使用するようです。
フォームフレームワークは開発に必須の機能であり、symfony 1.1を使うのであれば、使用方法を覚える必要があります。また新しく覚えることが増えてしまいますが、symfony 1.1を使うのであれば、避けては通れない道です。
1.1 からフォーム周りがどうも大きく変更されているようです。setteings.yml で
compat_10:              on
とかすると 1.0 の形式でもいけそうなのですが、せっかくなので最新バージョンのやり方で覚えたいと思います。
The Definitive Guide to symfonyの翻訳
公式サイトにaskeetと呼ばれる24日分のチュートリアルが存在しますが、askeet公開時点と比べてsymfonyが0.6系から1.0系と大きくバージョンアップされており、できれば1.0系で動作が確認されている他の最新のチュートリアルから始めることをお勧めしております。
ということで下記のチュートリアルをやることにします。
MyFirstSymfonyProjectJapanese &#8211; symfony &#8211; Trac
]]></description>
			<content:encoded><![CDATA[<p>今日 askeet の6日目をやっていたのですが、askeet はとりあえずやめることにしました。</p>
<p>6日目はバリデーションの実装なのですが、どうも symfony1.1 からバリデーションの実装方法が結構変わっているようです。</p>
<p>validate ディレクトリに yml ファイルでバリデーションを定義してもちっとも有効にならず悩んでいたのですが、下記のような記事を見つけました。<br />
<a href="http://www.thinkit.co.jp/article/71/3/" target="_blank" class="liexternal">[Think IT] 第3回：フォームフレームワークを使おう！ (1/3)</a><br />
<span id="more-479"></span><br />
上記記事によると 1.1 ではフォームフレームワークを使用するようです。</p>
<blockquote><p>フォームフレームワークは開発に必須の機能であり、symfony 1.1を使うのであれば、使用方法を覚える必要があります。また新しく覚えることが増えてしまいますが、symfony 1.1を使うのであれば、避けては通れない道です。</p></blockquote>
<p>1.1 からフォーム周りがどうも大きく変更されているようです。setteings.yml で<br />
<code>compat_10:              on</code><br />
とかすると 1.0 の形式でもいけそうなのですが、せっかくなので最新バージョンのやり方で覚えたいと思います。</p>
<p><a href="http://symfony.xrea.jp/" target="_blank" class="liexternal">The Definitive Guide to symfonyの翻訳</a></p>
<blockquote><p>公式サイトにaskeetと呼ばれる24日分のチュートリアルが存在しますが、askeet公開時点と比べてsymfonyが0.6系から1.0系と大きくバージョンアップされており、できれば1.0系で動作が確認されている他の最新のチュートリアルから始めることをお勧めしております。</p></blockquote>
<p>ということで下記のチュートリアルをやることにします。<br />
<a href="http://trac.symfony-project.org/wiki/MyFirstSymfonyProjectJapanese" target="_blank" class="liexternal">MyFirstSymfonyProjectJapanese &#8211; symfony &#8211; Trac</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/479/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet 5日目</title>
		<link>http://www.syuhari.jp/blog/archives/475</link>
		<comments>http://www.syuhari.jp/blog/archives/475#comments</comments>
		<pubDate>Fri, 04 Jul 2008 02:18:45 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[Logo]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[Pager]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[Word]]></category>
		<category><![CDATA[yml]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=475</guid>
		<description><![CDATA[5日目はログイン処理の追加とページ処理です。
ログイン処理
ログインリンク追加
askeet/apps/frontend/templates/layout.php
about のリンクの前に入れる
&#60;li&#62;&#60;?php echo link_to('sign in', 'user/login') ?&#62;&#60;/li&#62;

デバッグモードだと symfony のツールバーにログインのリンクが隠れてしまう。[sf]ボタンをクリックするとデバッグ用のツールバーを隠すことができます。
ユーザモジュールの追加
symfony init-module frontend user
上記コマンドを実行すると下記のようなファイルが作成されます。

&#62;&#62; dir+      /home/askeet/apps/frontend/modules/user/actions
&#62;&#62; file+     /home/askeet/apps/frontend/modu.../user/actions/actions.class.php
&#62;&#62; dir+      /home/askeet/apps/frontend/modules/user/templates
&#62;&#62; file+     /home/askeet/apps/frontend/modu...user/templates/indexSuccess.php
&#62;&#62; file+     /home/askeet/test/functional/frontend/userActionsTest.php
&#62;&#62; tokens    /home/askeet/test/functional/frontend/userActionsTest.php
&#62;&#62; tokens    /home/askeet/apps/frontend/modu.../user/actions/actions.class.php
&#62;&#62; tokens [...]]]></description>
			<content:encoded><![CDATA[<p>5日目はログイン処理の追加とページ処理です。</p>
<h4>ログイン処理</h4>
<h5>ログインリンク追加</h5>
<p>askeet/apps/frontend/templates/layout.php<br />
about のリンクの前に入れる</p>
<pre class="php" name="code">&lt;li&gt;&lt;?php echo link_to('sign in', 'user/login') ?&gt;&lt;/li&gt;</pre>
<p><span id="more-475"></span><br />
デバッグモードだと symfony のツールバーにログインのリンクが隠れてしまう。[sf]ボタンをクリックするとデバッグ用のツールバーを隠すことができます。</p>
<h5>ユーザモジュールの追加</h5>
<pre class="shell">symfony init-module frontend user</pre>
<p>上記コマンドを実行すると下記のようなファイルが作成されます。</p>
<pre class="shell">
&gt;&gt; dir+      /home/askeet/apps/frontend/modules/user/actions
&gt;&gt; file+     /home/askeet/apps/frontend/modu.../user/actions/actions.class.php
&gt;&gt; dir+      /home/askeet/apps/frontend/modules/user/templates
&gt;&gt; file+     /home/askeet/apps/frontend/modu...user/templates/indexSuccess.php
&gt;&gt; file+     /home/askeet/test/functional/frontend/userActionsTest.php
&gt;&gt; tokens    /home/askeet/test/functional/frontend/userActionsTest.php
&gt;&gt; tokens    /home/askeet/apps/frontend/modu.../user/actions/actions.class.php
&gt;&gt; tokens    /home/askeet/apps/frontend/modu...user/templates/indexSuccess.php
</pre>
<h5>ログインアクション</h5>
<p>askeet/apps/frontend/modules/user/actions/actions.class.php</p>
<pre class="php" name="code">
public function executeLogin()
{
  $this-&gt;getRequest()-&gt;setAttribute('referer', $this-&gt;getRequest()-&gt;getReferer());

  return sfView::SUCCESS;
}
</pre>
<p>これは仮の処理でとりあえずログインフォームを表示するだけの処理です。</p>
<h5>ログインビュー</h5>
<p>ログインフォームを表示するビューを作成します。<br />
askeet/apps/frontend/modules/user/templates/loginSuccess.php</p>
<pre class="php" name="code">
&lt;?php echo form_tag('user/login') ?&gt;

  &lt;fieldset&gt;

  &lt;div class=&quot;form-row&quot;&gt;
    &lt;label for=&quot;nickname&quot;&gt;nickname:&lt;/label&gt;
    &lt;?php echo input_tag('nickname', $sf_params-&gt;get('nickname')) ?&gt;
  &lt;/div&gt;

  &lt;div class=&quot;form-row&quot;&gt;
    &lt;label for=&quot;password&quot;&gt;password:&lt;/label&gt;
    &lt;?php echo input_password_tag('password') ?&gt;
  &lt;/div&gt;

  &lt;/fieldset&gt;

  &lt;?php echo input_hidden_tag('referer', $sf_request-&gt;getAttribute('referer')) ?&gt;
  &lt;?php echo submit_tag('sign in') ?&gt;

&lt;/form&gt;
</pre>
<p>さっそく先ほど作成したリンクからログインフォームを表示させてみると<br />
Call to undefined function form_tag()<br />
とエラーになった。Form ヘルパーが使えていないようです。<br />
調べたところ</p>
<pre class="php" name="code">
&lt;?php use_helper('Form'); ?&gt;
</pre>
<p>として使用するヘルパーを宣言しないといけないようです。バージョンが変わってデフォルトで使用できるヘルパーが変わったのでしょうか。</p>
<p>これでログインフォームが表示できるようになりました。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/login.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/login-300x145.png" alt="" title="login" width="300" height="145" class="alignnone size-medium wp-image-476 screenshot" /></a></p>
<h5>ログイン処理</h5>
<p>先ほど仮に入れた処理を削除してログイン処理を実装します。<br />
しかし、まだデータベースにパスワードフィールドがないので存在するユーザならパスワードが何でも認証します。<br />
askeet/apps/frontend/modules/user/templates/loginSuccess.php</p>
<pre class="php" name="code">
public function executeLogin()
{
  if ($this-&gt;getRequest()-&gt;getMethod() != sfRequest::POST)
  {
    // display the form
    $this-&gt;getRequest()-&gt;setAttribute('referer', $this-&gt;getRequest()-&gt;getReferer());
  }
  else
  {
    // handle the form submission
    $nickname = $this-&gt;getRequestParameter('nickname');

    $c = new Criteria();
    $c-&gt;add(UserPeer::NICKNAME, $nickname);
    $user = UserPeer::doSelectOne($c);

    // nickname exists?
    if ($user)
    {
      // password is OK?
      if (true)
      {
        $this-&gt;getUser()-&gt;setAuthenticated(true);
        $this-&gt;getUser()-&gt;addCredential('subscriber');

        $this-&gt;getUser()-&gt;setAttribute('subscriber_id', $user-&gt;getId(), 'subscriber');
        $this-&gt;getUser()-&gt;setAttribute('nickname', $user-&gt;getNickname(), 'subscriber');

        // redirect to last page
        return $this-&gt;redirect($this-&gt;getRequestParameter('referer', '@homepage'));
      }
    }
  }
}
</pre>
<h5>ログアウト処理</h5>
<pre class="php" name="code">
public function executeLogout()
{
  $this-&gt;getUser()-&gt;setAuthenticated(false);
  $this-&gt;getUser()-&gt;clearCredentials();
  $this-&gt;getUser()-&gt;getAttributeHolder()-&gt;removeNamespace('subscriber');
  $this-&gt;redirect('@homepage');
}
</pre>
<h5>レイアウトの変更</h5>
<p>ログイン状態によってログインフォームへのリンク部分を変更するようにレイアウトを変更します。</p>
<pre class="php" name="code">
&lt;?php if ($sf_user-&gt;isAuthenticated()): ?&gt;
  &lt;li&gt;&lt;?php echo link_to('sign out', 'user/logout') ?&gt;&lt;/li&gt;
  &lt;li&gt;&lt;?php echo link_to($sf_user-&gt;getAttribute('nickname', '', 'subscriber').' profile', 'user/profile') ?&gt;&lt;/li&gt;
&lt;?php else: ?&gt;
  &lt;li&gt;&lt;?php echo link_to('sign in/register', 'user/login') ?&gt;&lt;/li&gt;
&lt;?php endif ?&gt;
</pre>
<p>ログインしていない場合は[sign in/register]を表示し、ログインしている場合は[sign out]とログインしているユーザ名を表示しリンク先をプロフィール表示画面にします。</p>
<h5>実際にログインしてみる</h5>
<p>テストデータを見るとユーザが3名ほど登録されています。その中から[fabpot]というユーザでログインしてみます。nicknameに[fabpot]、パスワードは空で[sign in]ボタンをクリックすると認証後に質問一覧ページにリダイレクトされました。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/login_ok.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/login_ok-300x145.png" alt="" title="login_ok" width="300" height="145" class="alignnone size-medium wp-image-477 screenshot" /></a></p>
<h4>ページ処理</h4>
<h5>一覧表示アクションの修正</h5>
<p>1ページに表示する質問数を取得してページ処理する処理を追加する<br />
askeet/apps/frontend/modules/question/actions.class.php</p>
<pre class="php" name="code">
public function executeIndex ()
{
  $pager = new sfPropelPager('Question', sfConfig::get('app_pager_homepage_max'));

  $c = new Criteria();
  $c-&gt;addDescendingOrderByColumn(QuestionPeer::INTERESTED_USERS);
  $pager-&gt;setCriteria($c);
  $pager-&gt;setPage($this-&gt;getRequestParameter('page', 1));
  $pager-&gt;setPeerMethod('doSelectJoinUser');
  $pager-&gt;init();

  $this-&gt;question_pager = $pager;
}
</pre>
<h5>アプリケーション設定ファイルを変更</h5>
<p>設定ファイル(app.yml) に1ページに表示する質問数を追加する<br />
askeet/apps/frontend/config/app.yml</p>
<pre class="php" name="code">
all:
  pager:
    homepage_max: 2
</pre>
<p>この設定を取得するには下記のようにします。</p>
<pre class="php" name="code">
sfConfig::get('app_pager_homepage_max')
</pre>
<p>これで &#8216;2&#8242; が取得できる。この部分は1ページの質問数を設定している部分です。現在3つしか質問がないので1ページに2つの質問を表示することによりページング処理のテストを行います。</p>
<h5>ビューの変更</h5>
<p>一覧を表示する foreach の部分を下記に変更。これでページ処理された一覧を取得。</p>
<pre class="php" name="code">
&lt;?php foreach($question_pager-&gt;getResults() as $question): ?&gt;
</pre>
<p>一覧の下にページナビゲーションを追加</p>
<pre class="php" name="code">
&lt;div id=&quot;question_pager&quot;&gt;
&lt;?php if ($question_pager-&gt;haveToPaginate()): ?&gt;
  &lt;?php echo link_to('&amp;laquo;', 'question/list?page=1') ?&gt;
  &lt;?php echo link_to('&amp;lt;', 'question/list?page='.$question_pager-&gt;getPreviousPage()) ?&gt;

  &lt;?php foreach ($question_pager-&gt;getLinks() as $page): ?&gt;
    &lt;?php echo link_to_unless($page == $question_pager-&gt;getPage(), $page, 'question/list?page='.$page) ?&gt;
    &lt;?php echo ($page != $question_pager-&gt;getCurrentMaxLink()) ? '-' : '' ?&gt;
  &lt;?php endforeach; ?&gt;

  &lt;?php echo link_to('&amp;gt;', 'question/list?page='.$question_pager-&gt;getNextPage()) ?&gt;
  &lt;?php echo link_to('&amp;raquo;', 'question/list?page='.$question_pager-&gt;getLastPage()) ?&gt;
&lt;?php endif; ?&gt;
&lt;/div&gt;
</pre>
<p><a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/pager.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/pager-300x145.png" alt="" title="pager" width="300" height="145" class="alignnone size-medium wp-image-478 screenshot" /></a></p>
<h5>ルーティングの変更</h5>
<p>apps/frontend/config/routing.yml </p>
<pre class="php" name="code">
popular_questions:
  url:   /index/:page
  param: { module: question, action: list } 

login:
  url:   /login
  param: { module: user, action: login }
</pre>
<h5>リファクタリング</h5>
<p>（チュートリアル通りなので省略）</p>
<p>ここまで進めてきて自分の環境とチュートリアルの環境が違う（question/list アクションが index だったり）のがどうもやりにくいので合せることにしました。</p>
<p>SVNレポジトリより routing.yml を落としてきてまずルーティングを合せました。<br />
次に question コントローラの index アクションを list アクションに変更、indexSccess.php を listSuccess.php に変更。<br />
これですっきりしました。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/475/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet 4日目</title>
		<link>http://www.syuhari.jp/blog/archives/472</link>
		<comments>http://www.syuhari.jp/blog/archives/472#comments</comments>
		<pubDate>Thu, 03 Jul 2008 02:16:30 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Tab]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[yml]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=472</guid>
		<description><![CDATA[4日目です。
昨日までに作成した質問の一覧画面から質問の個別表示ページ
http://askeet/frontend_dev.php/question/show/id/1
にアクセスするとエラーになる。調べると show アクションもビューもない。

そこで actions.class.php に下記コードを追加

public function executeShow()
{
   $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('id'));
   $this->forward404Unless($this->question);
}

askeet/apps/frontend/modules/question/templates/showSuccess.php を作成する

&#60;?php use_helper('Date') ?&#62;

&#60;div class=&#34;interested_block&#34;&#62;
  &#60;div class=&#34;interested_mark&#34;&#62;
    &#60;?php echo count($question-&#62;getInterests()) ?&#62;
  &#60;/div&#62;
&#60;/div&#62;

&#60;h2&#62;&#60;?php echo $question-&#62;getTitle() ?&#62;&#60;/h2&#62;

&#60;div class=&#34;question_body&#34;&#62;
  &#60;?php echo $question-&#62;getBody() ?&#62;
&#60;/div&#62;

&#60;div id=&#34;answers&#34;&#62;
&#60;?php foreach ($question-&#62;getAnswers() as $answer): ?&#62;
  &#60;div class=&#34;answer&#34;&#62;
    posted by &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>4日目です。</p>
<p>昨日までに作成した質問の一覧画面から質問の個別表示ページ<br />
http://askeet/frontend_dev.php/question/show/id/1<br />
にアクセスするとエラーになる。調べると show アクションもビューもない。<br />
<span id="more-472"></span><br />
そこで actions.class.php に下記コードを追加</p>
<pre class="php" name="code">
public function executeShow()
{
   $this->question = QuestionPeer::retrieveByPk($this->getRequestParameter('id'));
   $this->forward404Unless($this->question);
}
</pre>
<p>askeet/apps/frontend/modules/question/templates/showSuccess.php を作成する</p>
<pre class="php" name="code">
&lt;?php use_helper('Date') ?&gt;

&lt;div class=&quot;interested_block&quot;&gt;
  &lt;div class=&quot;interested_mark&quot;&gt;
    &lt;?php echo count($question-&gt;getInterests()) ?&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;&lt;?php echo $question-&gt;getTitle() ?&gt;&lt;/h2&gt;

&lt;div class=&quot;question_body&quot;&gt;
  &lt;?php echo $question-&gt;getBody() ?&gt;
&lt;/div&gt;

&lt;div id=&quot;answers&quot;&gt;
&lt;?php foreach ($question-&gt;getAnswers() as $answer): ?&gt;
  &lt;div class=&quot;answer&quot;&gt;
    posted by &lt;?php echo $answer-&gt;getUser()-&gt;getFirstName().' '.$answer-&gt;getUser()-&gt;getLastName() ?&gt;
    on &lt;?php echo format_date($answer-&gt;getCreatedAt(), 'p') ?&gt;
    &lt;div&gt;
      &lt;?php echo $answer-&gt;getBody() ?&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;?php endforeach; ?&gt;
&lt;/div&gt;
</pre>
<p>再度 http://askeet/frontend_dev.php/question/show/id/1 にアクセスすると表示できました。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/show.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/show-300x145.png" alt="" title="show" width="300" height="145" class="alignnone size-medium wp-image-473 screenshot" /></a></p>
<h4>URL からのパラメータの受け取り方</h4>
<p>URL が <strong>http://askeet/frontend_dev.php/question/show/id/1</strong> の場合</p>
<pre class="php" name="code">$id = $this->getRequestParameter('id')</pre>
<p>これで $id=1 になる。</p>
<p><strong>http://askeet/frontend_dev.php/question/show/id/1/myparam/myvalue</strong></p>
<pre class="php" name="code">$param = $this->getRequestParameter('myparam');</pre>
<p>これで $param = &#8216;myvalue&#8217; になる。</p>
<h4>テストデータの追加</h4>
<p>answer テーブルにデータを追加するために <strong>askeet/data/fixtures/test_data.yml</strong> にチュートリアルにあるデータを追加して symfony コマンドを実行</p>
<pre class="shell">symfony propel-load-data frontend</pre>
<p>データ追加後の画面表示<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/answer.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/answer-300x145.png" alt="" title="answer" width="300" height="145" class="alignnone size-medium wp-image-474 screenshot" /></a><br />
追加した回答データが表示されている。</p>
<p>注意点は <strong>symfony propel-load-data</strong> コマンドを実行するとDBから一度データを全て削除して insert しなおすので各データの ID が変わります。そのために URL の /show/id/x の x の部分もデータをロードするたびに変わります。</p>
<h4>モデルの変更</h4>
<p>ユーザ名をビューで組み立てるのではなくモデルで組み立てる<br />
<strong>askeet/lib/model/User.php</strong></p>
<pre class="php" name="code">
public function __toString()
{
  return $this->getFirstName().' '.$this->getLastName();
}
</pre>
<p><strong>askeet/frontend/modules/question/templates/showSuccess.php</strong></p>
<pre class="php" name="code">
posted by &lt;?php echo $answer-&gt;getUser()-&gt;getFirstName().' '.$answer-&gt;getUser()-&gt;getLastName() ?&gt;
</pre>
<p>という部分を下記に変更する</p>
<pre class="php" name="code">
posted by &lt;?php echo $answer-&gt;getUser() ?&gt;
</pre>
<p>__toString というマジックメソッドにすることによりビューでは User クラスのインスタンスを echo するだけでフルネームが表示できるようになりました。</p>
<p>マジックメソッドに関しては過去のエントリを参照<br />
<a href="http://www.syuhari.jp/blog/archives/453" class="liinternal">PHP5 マジックメソッド</a></p>
<h4>リファクタリング</h4>
<p>ビューの showSuccess.php と listSuccess.php には重複している部分があります。</p>
<pre class="php" name="code">&lt;div class=&quot;interested_block&quot;&gt;
  &lt;div class=&quot;interested_mark&quot;&gt;
    &lt;?php echo count($question-&gt;getInterests()) ?&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre>
<p>上記コードを <strong>askeet/apps/frontend/modules/question/templates/_interested_user.php</strong> というファイル名で作成して、<br />
showSuccess.php と listSuccess.php の該当部分を下記コードに修正します。</p>
<pre class="php" name="code">&lt;?php include_partial('interested_user', array('question' =&gt; $question)) ?&gt;</pre>
<p>この _interested_user.php のようなファイルをパーシャルといい、ファイル名の先頭はアンダースコアにして、ビューからインクルードするときはアンダースコアを入れずに指定します。第2引数にパーシャルに渡す引数を指定できます。パーシャルは HTML の共通化をするときに用いられます。</p>
<h4>モデルの変更（テーブルにカラムを追加）</h4>
<p>schema.yml の ask_question テーブルに下記の行を追加</p>
<pre class="php" name="code">interested_users: { type: integer, default: '0' }</pre>
<p>下記コマンドを実行してテーブルを再作成</p>
<pre class="shell">symfony propel-build-all</pre>
<p>データを再度挿入</p>
<pre class="shell">symfony propel-load-data frontend</pre>
<p>（このやり方でいいのかな？間違っていたらコメントで教えてください）</p>
<p>追加したカラムに Interest テーブルにレコードが追加される度に更新されるようにする<br />
<strong>askeet/lib/model/Interest.php</strong></p>
<pre class="php" name="code">
public function save($con = null)
{
  $con = Propel::getConnection();
  try
  {
    $con->begin();

    $ret = parent::save($con);

    // update interested_users in question table
    $question = $this->getQuestion();
    $interested_users = $question->getInterestedUsers();
    $question->setInterestedUsers($interested_users + 1);
    $question->save($con);

    $con->commit();

    return $ret;
  }
  catch (Exception $e)
  {
    $con->rollback();
    throw $e;
  }
}</pre>
<p>上記コードはトランザクションを使っています。</p>
<p>テンプレートの変更<br />
_interested_user.php </p>
<pre class="php" name="code">&lt;?php echo count($question-&gt;getInterests() ?&gt;</pre>
<p>を</p>
<pre class="php" name="code">&lt;?php echo $question-&gt;getInterestedUsers() ?&gt;</pre>
<p>に変更する</p>
<p>このままで質問を再表示させると interested_users カラムには何も入っていないので関心数が表示されません。そこで再度データを挿入しなおします。</p>
<pre class="shell">symfony propel-load-data frontend</pre>
<h4>回答モデルにも同じことをする</h4>
<p>これは繰り返しなので省略</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/472/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet 3日目</title>
		<link>http://www.syuhari.jp/blog/archives/468</link>
		<comments>http://www.syuhari.jp/blog/archives/468#comments</comments>
		<pubDate>Wed, 02 Jul 2008 07:00:23 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[truncate]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[yml]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=468</guid>
		<description><![CDATA[3日目をやってみてどうもバージョンの違いのためかチュートリアルに書かれている内容と実際にいじっているコードで違いが結構あるのに気がついた。そこで今回から違う点についても少し書いておきます。（askeet の symfony のバージョンは 1.0 、実際にいじっている symfony のバージョンは 1.1 です。）
MVC モデル
MVC の各ファイルの場所

モデル
askeet/lib/model/
ビュー
askeet/apps/frontend/modules/question/templates/
コントローラ
askeet/apps/frontend/modules/question/actions/


レイアウトの変更
askeet/apps/frontend/templates/layout.php がアプリのレイアウトになる。このファイルをチュートリアルに書かれているコードに修正する。
また、CSS（main.css, layout.css) を チュートリアルの SVN レポジトリからダウンロードして askeet/web/css に入れる。
追加した CSS をレイアウトで読み込むようにビューの設定ファイルを修正
frontend/config/view.yml
stylesheets: [main, layout]
CSS を追加した画面です。

テストデータ
askeet/data/fixtures/test_data.yml を作成
チュートリアルにあるように batch プログラムを作るが askeet/apps/frontend/config/config.php がないとエラーになる。調べてたところ下記コマンドでテストデータを読み込めました。
symfony propel-load-data frontend
バージョンの違いによるものと思います。
テストデータ入れた後の画面です。

ビューの変更
チュートリアルで変更しているビューは listSuccess.php だが該当のファイルはない。askeet/apps/frontend/modules/question/templates/indexSuccess.php が該当のファイルになるようです。
ビューを下記コードに変更する。
&#60;?php use_helper('Text') ?&#62;

&#60;h1&#62;popular questions&#60;/h1&#62; 

&#60;?php foreach($questionList as $question): ?&#62;
  &#60;div class=&#34;question&#34;&#62;
    &#60;div class=&#34;interested_block&#34;&#62;
     [...]]]></description>
			<content:encoded><![CDATA[<p>3日目をやってみてどうもバージョンの違いのためかチュートリアルに書かれている内容と実際にいじっているコードで違いが結構あるのに気がついた。そこで今回から違う点についても少し書いておきます。（askeet の symfony のバージョンは 1.0 、実際にいじっている symfony のバージョンは 1.1 です。）</p>
<h4>MVC モデル</h4>
<h5>MVC の各ファイルの場所</h5>
<dl>
<dt>モデル</dt>
<dd>askeet/lib/model/</dd>
<dt>ビュー</dt>
<dd>askeet/apps/frontend/modules/question/templates/</dd>
<dt>コントローラ</dt>
<dd>askeet/apps/frontend/modules/question/actions/</dd>
</dl>
<p><span id="more-468"></span></p>
<h4>レイアウトの変更</h4>
<p><strong>askeet/apps/frontend/templates/layout.php</strong> がアプリのレイアウトになる。このファイルをチュートリアルに書かれているコードに修正する。<br />
また、CSS（main.css, layout.css) を チュートリアルの <a href="http://svn.askeet.com/tags/release_day_3/web/css/" target="_blank" class="liexternal">SVN レポジトリ</a>からダウンロードして askeet/web/css に入れる。</p>
<p>追加した CSS をレイアウトで読み込むようにビューの設定ファイルを修正<br />
<strong>frontend/config/view.yml</strong></p>
<pre class="php" name="code">stylesheets: [main, layout]</pre>
<p>CSS を追加した画面です。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/style.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/style-300x145.png" alt="" title="style" width="300" height="145" class="alignnone size-medium wp-image-469 screenshot" /></a></p>
<h4>テストデータ</h4>
<p><strong>askeet/data/fixtures/test_data.yml </strong>を作成<br />
チュートリアルにあるように batch プログラムを作るが askeet/apps/frontend/config/config.php がないとエラーになる。調べてたところ下記コマンドでテストデータを読み込めました。</p>
<pre class="shell">symfony propel-load-data frontend</pre>
<p>バージョンの違いによるものと思います。</p>
<p>テストデータ入れた後の画面です。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/test_data.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/test_data-300x163.png" alt="" title="test_data" width="300" height="163" class="alignnone size-medium wp-image-470 screenshot" /></a></p>
<h4>ビューの変更</h4>
<p>チュートリアルで変更しているビューは listSuccess.php だが該当のファイルはない。askeet/apps/frontend/modules/question/templates/indexSuccess.php が該当のファイルになるようです。<br />
ビューを下記コードに変更する。</p>
<pre class="php" name="code">&lt;?php use_helper('Text') ?&gt;

&lt;h1&gt;popular questions&lt;/h1&gt; 

&lt;?php foreach($questionList as $question): ?&gt;
  &lt;div class=&quot;question&quot;&gt;
    &lt;div class=&quot;interested_block&quot;&gt;
      &lt;div class=&quot;interested_mark&quot; id=&quot;interested_in_&lt;?php echo $question-&gt;getId() ?&gt;&quot;&gt;
        &lt;?php echo count($question-&gt;getInterests()) ?&gt;
      &lt;/div&gt;
    &lt;/div&gt;

    &lt;h2&gt;&lt;?php echo link_to($question-&gt;getTitle(), 'question/show?id='.$question-&gt;getId()) ?&gt;&lt;/h2&gt;

    &lt;div class=&quot;question_body&quot;&gt;
      &lt;?php echo truncate_text($question-&gt;getBody(), 200) ?&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;?php endforeach; ?&gt;</pre>
<p>また、コントローラからビューへ渡される変数名は $questions ではなく $questionList になります。（上記ソースは $questionList に変更してあります）</p>
<p>ここまでの画面です。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/popular.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/popular-300x126.png" alt="" title="popular" width="300" height="126" class="alignnone size-medium wp-image-471 screenshot" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/468/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet 2日目</title>
		<link>http://www.syuhari.jp/blog/archives/463</link>
		<comments>http://www.syuhari.jp/blog/archives/463#comments</comments>
		<pubDate>Tue, 01 Jul 2008 02:49:35 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tab]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[Word]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[yml]]></category>
		<category><![CDATA[本]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=463</guid>
		<description><![CDATA[無事デバッグモードも表示できたので askeet 2日目に進みました。
データベースの設定
データベース askeet を作成

$ mysqladmin -u username -p --default-character-set=utf8 create askeet


databases.yml を設定
全てコメントアウトされているのでコメントをはずしてdsn を修正、最後に encoding: utf8 を追加

all:
  propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://username:password@localhost/askeet
   [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.syuhari.jp/blog/archives/459" class="liinternal">無事デバッグモードも表示できた</a>ので askeet 2日目に進みました。</p>
<h4>データベースの設定</h4>
<h5>データベース askeet を作成</h5>
<pre class="shell">
$ mysqladmin -u username -p --default-character-set=utf8 create askeet
</pre>
<p><span id="more-463"></span></p>
<h5>databases.yml を設定</h5>
<p>全てコメントアウトされているのでコメントをはずしてdsn を修正、最後に encoding: utf8 を追加</p>
<pre class="php" name="code">
all:
  propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://username:password@localhost/askeet
      encoding:     utf8
</pre>
<h5>schema.yml 設定</h5>
<p>schema.xml を作成して schema.yml を作成する方法が書かれていますが、面倒なので直接 askeet/config/schema.yml を作成しました。</p>
<h5>propel.ini の下記の部分を修正</h5>
<pre class="php" name="code">
propel.database.createUrl  = mysql://username:password@localhost/
propel.database.url        = mysql://username:password@localhost/askeet
</pre>
<h4>データベースとモデルの作成</h4>
<pre class="shell">
$ symfony propel-build-all
</pre>
<p>というコマンドでデータベース、モデルをいっぺんに作成。上記コマンドは下記コマンドをそれぞれ実行するようです。</p>
<ul>
<li>symfony propel-build-model</li>
<li>symfony propel-build-sql</li>
<li>symfony propel-insert-sql</li>
</ul>
<h4>CRUD の作成</h4>
<p>Scaffolding 機能を使用して CRUD 用のアクションメソッドと最低限のテンプレートを作成</p>
<pre class="shell">
$ symfony propel-generate-crud frondend question Question
</pre>
<p>http://askeet/question にアクセスすると一覧、新規登録、編集、削除ができる画面にアクセスできます。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/crud.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/crud-300x145.png" alt="" title="crud" width="300" height="145" class="alignnone size-medium wp-image-464" /></a><br />
試しにデータを入れたり、編集削除してみました。日本語も大丈夫ですね。</p>
<p>うまく表示できない場合はデバッグモード http://askeet/frontend_dev.php/question にアクセスするとエラーがどこで起きているか確認できます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/463/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet デバッグモードが表示できない件 [解決]</title>
		<link>http://www.syuhari.jp/blog/archives/461</link>
		<comments>http://www.syuhari.jp/blog/archives/461#comments</comments>
		<pubDate>Tue, 01 Jul 2008 01:51:57 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[debugmode]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=461</guid>
		<description><![CDATA[askeet 1日目の最後でデバッグモードを表示させると

Your are not allowed to access this file. Check frontend_dev.php for more information.

と表示されてしまう件ですが、解決しました。
原因は /home/askeet/web/frontend_dev.php の4行目～7行目で

if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1')))
{
  die('Your are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

となっていて他の IP からのアクセスを拒否していました。

デバッグモードなのでセキュリティ的にも当然なのですが、私は LAN 内に Linux サーバを置いて LAN 内からのみアクセスできるようにして他の端末のブラウザからアクセスしていたためにこれに引っかかってしまいました。
そこで、アクセスする端末のローカルIPアドレスを指定することにより無事デバッグモードが表示できるようになりました。

]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.syuhari.jp/blog/archives/459" class="liinternal">askeet 1日目</a>の最後でデバッグモードを表示させると</p>
<pre>
Your are not allowed to access this file. Check frontend_dev.php for more information.
</pre>
<p>と表示されてしまう件ですが、解決しました。</p>
<p>原因は /home/askeet/web/frontend_dev.php の4行目～7行目で</p>
<pre class="php" name="code">
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1')))
{
  die('Your are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
</pre>
<p>となっていて他の IP からのアクセスを拒否していました。<br />
<span id="more-461"></span><br />
デバッグモードなのでセキュリティ的にも当然なのですが、私は LAN 内に Linux サーバを置いて LAN 内からのみアクセスできるようにして他の端末のブラウザからアクセスしていたためにこれに引っかかってしまいました。</p>
<p>そこで、アクセスする端末のローカルIPアドレスを指定することにより無事デバッグモードが表示できるようになりました。</p>
<p><a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/symfony_dev.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/07/symfony_dev-300x165.png" alt="" title="symfony_dev" width="300" height="165" class="alignnone size-medium wp-image-462" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/461/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[symfony] askeet 1日目</title>
		<link>http://www.syuhari.jp/blog/archives/459</link>
		<comments>http://www.syuhari.jp/blog/archives/459#comments</comments>
		<pubDate>Mon, 30 Jun 2008 09:03:00 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[conf]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[httpd.conf]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[Tab]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[yml]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=459</guid>
		<description><![CDATA[symfony を学習するために askeet を順番にやっていくことにしました。まずは1日目です。

インストール
まず PEAR をアップデート

$ pear upgrade PEAR

symfony プロジェクトの PEAR チャネルを登録

$ pear channel-discover pear.symfony-project.com

symfony をインストール

$ pear install symfony/symfony

とここで

symfony/symfony requires PHP extension "dom"
No valid packages found
install failed
というエラーがでる

# yum install php-xml

で php-xml を入れると symfony をインストールできました。
インストールの確認をしておきます。

$ symfony -V
symfony version 1.1.0 (/usr/share/pear/symfony)

プロジェクトの作成
askeet プロジェクトのディレクトリを作成します。

$ mkdir /home/askeet
$ cd /home/askeet
$ symfony init-project askeet

作成したディレクトリで symfony コマンドを実行して adkeet プロジェクトを作成します。下記のようなファイルが作成されました。

>> dir+    [...]]]></description>
			<content:encoded><![CDATA[<p>symfony を学習するために askeet を順番にやっていくことにしました。まずは1日目です。<br />
<span id="more-459"></span></p>
<h4>インストール</h4>
<p>まず PEAR をアップデート</p>
<pre class="shell">
$ pear upgrade PEAR
</pre>
<p>symfony プロジェクトの PEAR チャネルを登録</p>
<pre class="shell">
$ pear channel-discover pear.symfony-project.com
</pre>
<p>symfony をインストール</p>
<pre class="shell">
$ pear install symfony/symfony
</pre>
<p>とここで</p>
<pre class="shell">
symfony/symfony requires PHP extension "dom"
No valid packages found
install failed</pre>
<p>というエラーがでる</p>
<pre class="shell">
# yum install php-xml
</pre>
<p>で php-xml を入れると symfony をインストールできました。<br />
インストールの確認をしておきます。</p>
<pre class="shell">
$ symfony -V
symfony version 1.1.0 (/usr/share/pear/symfony)
</pre>
<h4>プロジェクトの作成</h4>
<p>askeet プロジェクトのディレクトリを作成します。</p>
<pre class="shell">
$ mkdir /home/askeet
$ cd /home/askeet
$ symfony init-project askeet
</pre>
<p>作成したディレクトリで symfony コマンドを実行して adkeet プロジェクトを作成します。下記のようなファイルが作成されました。</p>
<pre class="shell">
>> dir+      /home/askeet/web
>> file+     /home/askeet/web/.htaccess
>> dir+      /home/askeet/web/images
>> dir+      /home/askeet/web/uploads
>> dir+      /home/askeet/web/uploads/assets
>> dir+      /home/askeet/web/js
>> file+     /home/askeet/web/robots.txt
>> dir+      /home/askeet/web/css
>> file+     /home/askeet/web/css/main.css
>> dir+      /home/askeet/config
>> file+     /home/askeet/config/properties.ini
>> file+     /home/askeet/config/ProjectConfiguration.class.php
>> file+     /home/askeet/config/databases.yml
>> file+     /home/askeet/config/propel.ini
>> file+     /home/askeet/config/schema.yml
>> file+     /home/askeet/config/rsync_exclude.txt
>> dir+      /home/askeet/plugins
>> dir+      /home/askeet/lib
>> dir+      /home/askeet/doc
>> dir+      /home/askeet/test
>> dir+      /home/askeet/test/functional
>> dir+      /home/askeet/test/bootstrap
>> file+     /home/askeet/test/bootstrap/functional.php
>> file+     /home/askeet/test/bootstrap/unit.php
>> dir+      /home/askeet/test/unit
>> dir+      /home/askeet/data
>> file+     /home/askeet/symfony
>> dir+      /home/askeet/log
>> dir+      /home/askeet/apps
>> dir+      /home/askeet/cache
>> tokens    /home/askeet/config/properties.ini
>> tokens    /home/askeet/config/propel.ini
>> tokens    /home/askeet/config/ProjectConfiguration.class.php
>> chmod 777 /home/askeet/cache
>> chmod 777 /home/askeet/log
>> chmod 777 /home/askeet/web/uploads
>> chmod 777 /home/askeet/symfony
>> chmod 777 /home/askeet/web/uploads/assets
</pre>
<p>次に frontend というアプリケーションを作成します。</p>
<pre class="shell">
symfony init-app frontend
</pre>
<p>アプリケーション用の下記ファイルが作成されました。</p>
<pre class="shell">
>> dir+      /home/askeet/apps/frontend/config
>> file+     /home/askeet/apps/frontend/config/app.yml
>> file+     /home/askeet/apps/frontend/config/settings.yml
>> file+     /home/askeet/apps/frontend/config/factories.yml
>> file+     /home/askeet/apps/frontend/config/security.yml
>> file+     /home/askeet/apps/frontend/config/filters.yml
>> file+     /home/askeet/apps/frontend/config/view.yml
>> file+     /home/askeet/apps/frontend/config/routing.yml
>> file+     /home/askeet/apps/frontend/config/cache.yml
>> file+     /home/askeet/apps/frontend/conf...licationConfiguration.class.php
>> dir+      /home/askeet/apps/frontend/modules
>> dir+      /home/askeet/apps/frontend/lib
>> file+     /home/askeet/apps/frontend/lib/myUser.class.php
>> dir+      /home/askeet/apps/frontend/i18n
>> dir+      /home/askeet/apps/frontend/templates
>> file+     /home/askeet/apps/frontend/templates/layout.php
>> tokens    /home/askeet/apps/frontend/config/settings.yml
>> file+     /home/askeet/web/index.php
>> file+     /home/askeet/web/frontend_dev.php
>> tokens    /home/askeet/web/index.php
>> tokens    /home/askeet/web/frontend_dev.php
>> rename    /home/askeet/apps/frontend/conf...frontendConfiguration.class.php
>> tokens    /home/askeet/apps/frontend/conf...frontendConfiguration.class.php
>> chmod 777 /home/askeet/cache
>> chmod 777 /home/askeet/log
>> chmod 777 /home/askeet/web/uploads
>> chmod 777 /home/askeet/symfony
>> chmod 777 /home/askeet/web/uploads/assets
>> dir+      /home/askeet/test/functional/frontend
</pre>
<h4>httpd.conf の設定</h4>
<p>作成したプロジェクトにアクセスできるように httpd.conf を設定します。</p>
<p>その前に PEAR のデータのパスを調べておきます</p>
<pre class="shell">
pear config-show
....
PEAR data directory            data_dir         /usr/share/pear/data
....
</pre>
<p>symfony のデフォルトの CSS や画像は symfony のデータディレクトリにあるので、そのデータディレクトリのパスを httpd.conf で指定するために必要です。私の環境では /usr/share/pear/data でした。</p>
<p>httpd.conf に以下を追加</p>
<pre class="shell">
&lt;VirtualHost *:80&gt;
  ServerName askeet
  DocumentRoot "/home/askeet/web"
  DirectoryIndex index.php
  Alias /sf /usr/share/pear/data/symfony/web/sf

  &lt;Directory "/home/askeet/web"&gt;
   AllowOverride All
  &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p>Alias /sf /usr/share/pear/data/symfony/web/sf の部分を先ほど調べたパスに合せます。<br />
設定後、設定を反映させるために Apache を再起動させます。</p>
<p>ここまでで http://askeet/ にアクセスすると下記のような画面になります。<br />
<a href="http://www.syuhari.jp/blog/wp-content/uploads/2008/06/symfony.png" ><img src="http://www.syuhari.jp/blog/wp-content/uploads/2008/06/symfony-300x172.png" alt="" title="symfony" width="300" height="172" class="alignnone size-medium wp-image-460" /></a></p>
<p>また、symfony ではデバッグモードというのがあるそうで<br />
http://askeet/frontend_dev.php/ にアクセスすると表示できるそうです。<br />
ただ、なぜか下記のようなエラーメッセージがでてしまいアクセスすることができませんでした。</p>
<pre>
Your are not allowed to access this file. Check frontend_dev.php for more information.
</pre>
<p>原因を調査中なのですが今日は時間切れのようなので明日続きを調べたいと思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/459/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>symfony x PHP を購入した</title>
		<link>http://www.syuhari.jp/blog/archives/458</link>
		<comments>http://www.syuhari.jp/blog/archives/458#comments</comments>
		<pubDate>Sun, 29 Jun 2008 07:38:41 +0000</pubDate>
		<dc:creator>matsuura</dc:creator>
				<category><![CDATA[symfony]]></category>
		<category><![CDATA[age]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[askeet]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[ec]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[OpenPNE]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[本]]></category>

		<guid isPermaLink="false">http://www.syuhari.jp/blog/?p=458</guid>
		<description><![CDATA[OpenPNE がバージョン3からフレームワークに symfony を採用するということで、少し symfony をいじろうかと思って「symfony×PHP」を買ってみました。
まだ、最初の方を読んだだけなのですが、パラパラと読みながら Askeet などもやってみようかなと思っています。とりあえず symfony をやるモチベーションをアップするためにブログに書いておいた。

ちょうど CakePHP 勉強会で yando さんの CakePHP と symfony の比較を聞いたばかりなので始めるにはいいタイミングかも。
symfony×PHP [LLフレームワークBooks] (LLフレームワークBOOKS # 3)
森川 穣
￥ 2,079
単行本（ソフトカバー）
技術評論社

]]></description>
			<content:encoded><![CDATA[<p>OpenPNE がバージョン3からフレームワークに symfony を採用するということで、少し symfony をいじろうかと思って「<a href="http://www.amazon.co.jp/symfony%C3%97PHP-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBooks-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBOOKS-3-%E6%A3%AE%E5%B7%9D/dp/4774132373%3FSubscriptionId%3D00ZZGWWEM6KCNNQ67M82%26tag%3D8109-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774132373" target="_blank" class="liexternal">symfony×PHP</a>」を買ってみました。</p>
<p>まだ、最初の方を読んだだけなのですが、パラパラと読みながら <a href="http://www.symfony-project.org/askeet/1_0/en/" target="_blank" class="liexternal">Askeet</a> などもやってみようかなと思っています。とりあえず symfony をやるモチベーションをアップするためにブログに書いておいた。<br />
<span id="more-458"></span><br />
ちょうど CakePHP 勉強会で yando さんの CakePHP と symfony の比較を聞いたばかりなので始めるにはいいタイミングかも。</p>
<h4><a href="http://www.amazon.co.jp/symfony%C3%97PHP-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBooks-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBOOKS-3-%E6%A3%AE%E5%B7%9D/dp/4774132373%3FSubscriptionId%3D00ZZGWWEM6KCNNQ67M82%26tag%3D8109-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774132373" target="_blank" class="liexternal">symfony×PHP [LLフレームワークBooks] (LLフレームワークBOOKS # 3)</a></h4>
<p><a href="http://www.amazon.co.jp/symfony%C3%97PHP-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBooks-LL%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%83%AF%E3%83%BC%E3%82%AFBOOKS-3-%E6%A3%AE%E5%B7%9D/dp/4774132373%3FSubscriptionId%3D00ZZGWWEM6KCNNQ67M82%26tag%3D8109-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774132373" target="_blank"><img src="http://ecx.images-amazon.com/images/I/41gbS%2BvOscL._SL160_.jpg" border="0" width="113" height="160" alt="symfony×PHP [LLフレームワークBooks] (LLフレームワークBOOKS # 3)" align="left" /></a>森川 穣<br />
￥ 2,079<br />
単行本（ソフトカバー）<br />
技術評論社<br />
<br clear="all"/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.syuhari.jp/blog/archives/458/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
