symfony askeet Day 7続き
- ナビゲーションバーを追加する
- view.ymlの設定
- 現状のファイル構成
ナビゲーションバーを追加する
よくあるメニューバーだったりするものですね。
これはどのページにも必要な構成要素なのでコンポーネントというと。
まずはページのレイアウトにsidebarを呼び出すコードを追加します。
場所はaskeet/apps/frontend/templates/layout.php
<div id="content_bar"> <!-- Nothing for the moment --> <div class="verticalalign"></div> </div>
これを
<?php include_component_slot('sidebar') ?>
に置き換えて終了。
次にview.ymlに定義をすると。
場所はaskeet/apps/frontend/config/view.yml
components: sidebar: [sidebar, default]
これをview.ymlに追加した。
次にアクションとテンプレートを書く。
まずはsidebarモジュールを作る。
symfony init-module frontend sidebar
できたら、askeet/apps/frontend/modules/sidebar/actions/actions.class.phpを開いて
以下のように書き換えてcomponents.class.phpとして保存。
<?php /** * sidebar components. * * @package askeet * @subpackage sidebar * @author Your name here * @version SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $ */ class sidebarComponents extends sfComponents { public function executeDefault() { } }
これができたら_default.phpを作る。
コンポーネントビューはフラグメントとして扱うので_default.phpという名前にするそうな。
場所はaskeet/apps/frontend/modules/sidebar/templates/_default.php
<?php echo link_to('ask a new question','question/add') ?> <ul> <li><?php echo link_to('popular questions','question/list') ?></li> <li><?php echo link_to('latest questions','question/recent') ?></li> <li><?php echo link_to('latest answers','answer/recent') ?></li> </ul>
本当に、単なるリンクだけですね。
設定が終わったので確認するためにキャッシュをクリアする。
symfony cc
view.ymlの設定
ぼーっと読んでいて気づいたのですが
metaタグ等を書かなくても全部ここに書けばいいんですね。
現在、symfony projectになっているタイトルなどの変更もここで行われると。
ということで早速修正。
場所はaskeet/apps/frontend/config/view.yml
default: http_metas: content-type: text/html; charset=utf-8 metas: title: askeet! Japan - 答えて質問,見つかるアンサー robots: index, follow description: askeet!はsymfony projectが24時間で作りました。 keywords: symfony, project, askeet, php5, question, answer language: en stylesheets: [main, layout] javascripts: [] has_layout: on layout: layout components: sidebar: [sidebar, default]
実際にこれをhtmlタグで書くと
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="title" content="askeet! Japan - 答えて質問,見つかるアンサー" /> <meta name="robots" content="index, follow" /> <meta name="description" content="askeet!はsymfony projectが24時間で作りました。" /> <meta name="keywords" content="symfony, project, askeet, php5, question, answer" /> <meta name="language" content="en" /> <title>askeet! Japan - 答えて質問,見つかるアンサー</title> <link rel="shortcut icon" href="/favicon.ico" /> <link rel="stylesheet" type="text/css" media="screen" href="/css/main.css" /> <link rel="stylesheet" type="text/css" media="screen" href="/css/layout.css" /> </head>
現状のファイル構成
増えたなー。でも、それほど書いていないのに。
. |-- apps | `-- frontend | |-- config | | |-- app.yml | | |-- cache.yml | | |-- config.php | | |-- factories.yml | | |-- filters.yml | | |-- i18n.yml | | |-- logging.yml | | |-- routing.yml | | |-- security.yml | | |-- settings.yml | | `-- view.yml | |-- i18n | |-- lib | | |-- helper | | | `-- GlobalHelper.php | | |-- myLoginValidator.class.php | | `-- myUser.class.php | |-- modules | | |-- answer | | | |-- actions | | | | `-- actions.class.php | | | |-- config | | | |-- lib | | | |-- templates | | | | |-- indexSuccess.php | | | | `-- recentSuccess.php | | | `-- validate | | |-- question | | | |-- actions | | | | `-- actions.class.php | | | |-- config | | | | `-- security.yml | | | `-- templates | | | |-- _interested_user.php | | | |-- _list.php | | | |-- listSuccess.php | | | |-- recentSuccess.php | | | `-- showSuccess.php | | |-- sidebar | | | |-- actions | | | | `-- components.class.php | | | |-- config | | | |-- lib | | | |-- templates | | | | `-- _default.php | | | `-- validate | | `-- user | | |-- actions | | | `-- actions.class.php | | |-- config | | |-- lib | | |-- templates | | | |-- loginSuccess.php | | | `-- showSuccess.php | | `-- validate | | `-- login.yml | `-- templates | `-- layout.php |-- batch | `-- load_data.php |-- cache | |-- frontend | | |-- dev | | | `-- config | | | |-- config_app.yml.php | | | |-- config_autoload.yml.php | | | |-- config_config_handlers.yml.php | | | |-- config_databases.yml.php | | | |-- config_factories.yml.php | | | |-- config_logging.yml.php | | | |-- config_php.yml.php | | | |-- config_routing.yml.php | | | |-- config_settings.yml.php | | | |-- modules_question_config_filters.yml.php | | | |-- modules_question_config_module.yml.php | | | |-- modules_question_config_security.yml.php | | | |-- modules_question_config_view.yml.php | | | `-- modules_sidebar_config_module.yml.php | | `-- prod | | `-- config | | |-- VERSION | | |-- config_app.yml.php | | |-- config_autoload.yml.php | | |-- config_bootstrap_compile.yml.php | | |-- config_config_handlers.yml.php | | |-- config_core_compile.yml.php | | |-- config_databases.yml.php | | |-- config_factories.yml.php | | |-- config_i18n.yml.php | | |-- config_logging.yml.php | | |-- config_php.yml.php | | |-- config_routing.yml.php | | |-- config_settings.yml.php | | |-- modules_question_config_filters.yml.php | | |-- modules_question_config_module.yml.php | | |-- modules_question_config_security.yml.php | | |-- modules_question_config_view.yml.php | | `-- modules_sidebar_config_module.yml.php | |-- svn-prop.tmp~ | `-- tmp | `-- f0b8de7655b876299b405752f4ff0c80 |-- config | |-- config.php | |-- databases.yml | |-- generated-schema-transformed.xml | |-- propel.ini | |-- properties.ini | |-- rsync_exclude.txt | `-- schema.yml |-- data | |-- fixtures | | `-- test_data.yml | |-- model | `-- sql | |-- lib.model.schema.sql | `-- sqldb.map |-- doc |-- lib | |-- model | | |-- Answer.php | | |-- AnswerPeer.php | | |-- Interest.php | | |-- InterestPeer.php | | |-- Question.php | | |-- QuestionPeer.php | | |-- Relevancy.php | | |-- RelevancyPeer.php | | |-- User.php | | |-- UserPeer.php | | |-- map | | | |-- AnswerMapBuilder.php | | | |-- InterestMapBuilder.php | | | |-- QuestionMapBuilder.php | | | |-- RelevancyMapBuilder.php | | | `-- UserMapBuilder.php | | `-- om | | |-- BaseAnswer.php | | |-- BaseAnswerPeer.php | | |-- BaseInterest.php | | |-- BaseInterestPeer.php | | |-- BaseQuestion.php | | |-- BaseQuestionPeer.php | | |-- BaseRelevancy.php | | |-- BaseRelevancyPeer.php | | |-- BaseUser.php | | `-- BaseUserPeer.php | `-- myTools.class.php |-- log | |-- frontend_dev.log | `-- svn-prop.tmp~ |-- plugins |-- symfony |-- test | |-- bootstrap | | |-- functional.php | | `-- unit.php | |-- functional | | `-- frontend | | |-- answerActionsTest.php | | |-- questionActionsTest.php | | |-- sidebarActionsTest.php | | `-- userActionsTest.php | `-- unit `-- web |-- css | |-- layout.css | `-- main.css |-- frontend_dev.php |-- images | |-- add_background.gif | |-- askeet_logo.gif | |-- content_top.gif | |-- feed.gif | |-- firebug.jpg | |-- first.gif | |-- footer_background.gif | |-- header_background.gif | |-- indicator.gif | |-- interested.jpg | |-- interested_bubble.gif | |-- last.gif | |-- login.jpg | |-- menu_left.gif | |-- new_background.gif | |-- next.gif | |-- previous.gif | |-- side_top.gif | |-- sidebar.jpg | |-- symfony.gif | |-- thumb_down.gif | `-- thumb_up.gif |-- index.php |-- js |-- robots.txt `-- uploads `-- assets 62 directories, 137 files