review askeet Day 3

frontendのレイアウトを変更する。

場所: askeet2/apps/frontend/templates/layout.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<?php include_http_metas() ?>
<?php include_metas() ?>

<?php include_title() ?>

<link rel="shortcut icon" href="/favicon.ico" />

</head>
<body>

<div id="header">
  <ul>
    <li><?php echo link_to('about','@homepage') ?></li>
  </ul>
  <h1><?php echo link_to(image_tag('askeet_logo.gif','alt=askeet'),'@homepage') ?></h1>
</div>

<div id="content">
  <div id="content_main">
    <?php echo $sf_data->getRaw('sf_content') ?>
    <div class="verticalalign"></div>
  </div>

  <div id="content_bar">
    <!-- Nothing for the moment -->
    <div class="verticalalign"></div>
  </div>
</div>

</body>
</html>
書き換えたらCSSを拾いに行く。

http://svn.askeet.com/tags/release_day_3/web/css/
ここからダウンロードする。askeet2/web/cssに移動して
main.cssを一度削除してからダウンロードする。

cd web/css
rm main.css
wget http://svn.askeet.com/tags/release_day_3/web/css/main.css
wget http://svn.askeet.com/tags/release_day_3/web/css/layout.css
layout.cssも表示できるようにする。

現状ではmain.cssしか当てられていないのでおかしい表示になっている。

場所: askeet2/apps/frontend/config/view.yml

  stylesheets:    [main, layout]

これでlayout.cssも読み込めるように。

これで問題なし><
画像がないのは今回はそのまま放置。

トップページの変更

現在はsymfonyのCongratulations画面なので
questionをトップページにします。
場所: askeet2/apps/frontend/config/routing.yml

# default rules
homepage:
  url:   /
  param: { module: question, action: list }

テストデータを用意する。

そのままテストデータを使ってもおもしろくないので多少弄る。
場所: askeet2/data/fixtures/test_data.yml

User:
  anonymous:
    nickname:   anonymous
    first_name: Anonymous
    last_name:  Coward

  crazyup:
    nickname:   crazyup
    first_name: Shota
    last_name:  Enomoto

  dinotaro:
    nickname:   dino
    first_name: Taro
    last_name:  Dino

Question:
  q1:
    title: What shall I do tonight with my girlfriend?
    user_id: crazyup
    body:  |
      We shall meet in front of the Dunkin'Donuts before dinner, 
      and I haven't the slightest idea of what I can do with her. 
      She's not interested in programming, space opera movies nor insects.
      She's kinda cute, so I really need to find something 
      that will keep her to my side for another evening.

  q2:
    title: What can I offer to my step mother?
    user_id: anonymous
    body:  |
      My stepmother has everything a stepmother is usually offered
      (watch, vacuum cleaner, earrings, del.icio.us account). 
      Her birthday comes next week, I am broke, and I know that 
      if I don't offer her something sweet, my girlfriend 
      won't look at me in the eyes for another month.

  q3:
    title: How can I generate traffic to my blog?
    user_id: dinotaro
    body:  |
      I have a very swell blog that talks 
      about my class and mates and pets and favorite movies.

Interest:
  i1: { user_id: crazyup, question_id: q1 }
  i2: { user_id: dinotaro, question_id: q1 }
  i3: { user_id: dinotaro, question_id: q2 }
  i4: { user_id: crazyup, question_id: q2 }

テストデータを入れるためのバッチを作る

場所: askeet2/batch/load_data.php

<?php

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
define('SF_APP',         'frontend');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG',       true);

require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.
             SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');

// データベースマネージャーを初期化する
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();

// fixturesにあるすべてのファイルを読み込みDBにデータを追加
$data = new sfPropelData();
$data->loadData(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures');

あとはこいつをコマンドラインから叩けばテストデータがDBへ。

php batch/load_data.php


入ってる><

テーブルからdivに変更

場所: askeet2/apps/frontend/templates/listSuccess.php

<?php use_helper('Text') ?>

<h1>人気の質問</h1>

<?php foreach($questions as $question): ?>

  <div class="question">
    <div class="interested_block">
      <div class="interested_mark" id="mark_<?php echo $question->getId() ?>">
   <?php echo count($question->getInterests()) ?>
      </div>
    </div>

    <h2><?php echo link_to($question->getTitle(),'question/show?id='.$question->getId()) ?></h2>

    <div class="question_body">
   <?php echo truncate_text($question->getBody(),200) ?>
    </div>

  </div>
<?php endforeach; ?>

link_toはaタグとかを書く必要が無くてすごく便利。
truncate_textはgetBodyを200文字に切り詰めて表示していると。

おーそれっぽい><

使わないコードやファイルを削除する。

あとあと実装するので邪魔なのは削除しておく。
まずはquestionのアクションのお掃除
場所: askeet2/apps/frontend/modules/question/actions/actions.class.php

<?php

/**
 * question actions.
 *
 * @package    askeet
 * @subpackage question
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 3335 2007-01-23 16:19:56Z fabien $
 */
class questionActions extends sfActions
{

  public function executeList()
  {
    $this->questions = QuestionPeer::doSelect(new Criteria());
  }

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

}

あとはeditSuccess.phpを削除

svn rm apps/frontend/modules/question/templates/editSuccess.php