ホーム > Web開発関連

symfonyでモバイル開発する際に参考になるだろうリンク


モバイル開発@symfony :: handsOut.jp がかなり良い感じ。以下コードを引用してみる。

apps/app_name/config/filters.yml

rendering: ~
web_debug: ~
security: ~
# generally, you will want to insert your own filters here
mobile:
  class: myMobileFilter
cache: ~
common: ~
flash: ~
execution:  

apps/app_name/config/autoload.yml

autoload:
  PEAR:
    name: PEAR
    files:
      Net_UserAgent_Mobile: /path/to/Net/UserAgent/Mobile.php

myMobileFilter.class.php (抜粋)

public function execute($filterChain) {
  // preFilter
  $request = $this­->getContext()­->getRequest();
  $response = $this­->getContext()­->getResponse();
  if ($this­->isFirstCall()) {
    $agent = @Net_UserAgent_Mobile::singleton();
    switch (true) {
      case $agent­->isDoCoMo():
        $carrier = 'docomo';
        $response­->setContentType('application/xhtml+xml; charset=Shift_JIS'); // 出力ヘッダを指定
        $response->addStylesheet('/path/to/docomo.css')// キャリア別のスタイルシートを指定
        break;
      case $agent­->isEzweb():
        $carrier = 'ezweb';
        $response->addStylesheet('/path/to/ezweb.css')// キャリア別のスタイルシートを指定
        // 中略
    }
    $request­->setAttribute('agent', $agent);
    $request­->setAttribute('carrier', $carrier);
    // sfPictogramMobilePlugin
    $pictogram = sfPictogramMobile::factory($carrier, 'utf­8');
    $request­->setAttribute('pictogram', $pictogram);
  }
 
  $filterChain-­>execute();
 
  // postFilter
  $content = $response­->getContent();
  $content = $request­->getAttribute('pictogram')­->replace($content);
  // 出力前に CSS をインライン展開
  if ($request­->getAttribute('carrier') == 'docomo') {
    $content = HTML_CSS_Mobile::getInstance()­->setBaseDir('/path/to/doc_root')­->apply($content);
  }
  $response­->setContent($content);
}

apps/app_name/templates/layout.php (抜粋)

<? include_partial('global/dtd'); ?>
<html xmlns="http://www.w3.org/1999 /xhtml" xml:lang="ja" lang="ja">
<head>

apps/app_name/templates/_dtd.php

<?php switch (sfContext::getInstance()­>getRequest()­>getAttribute('carrier')): ?>
<?php case 'docomo': ?><?php echo '<'; ?>?xml version="1.0" encoding="Shift_JIS" ?>
<!DOCTYPE html PUBLIC "­//i­mode group (ja)//DTD XHTML i­XHTML(Locale/Ver.=ja/1.1) 1.0//EN" "i­xhtml_4ja_10.dtd">
<?php break; ?>
<?php case 'ezweb': ?>
<?php echo '<'; ?>?xml version="1.0" encoding="Shift_JIS" ?>
<!DOCTYPE html PUBLIC "­//OPENWAVE//DTD XHTML 1.0//EN" "http://www.openwave.com/DTD/xhtml­basic.dtd">
// 以下略

他にも helper を使って、mailto や input 要素の問題などを吸収する方法や、モバイルのセッションを、SessionStorage を使って解決する方法が書いてある。

以下のファイルを作成、編集
apps/app_name/lib/helper/MobileHelper.php
apps/app_name/lib/myMobileFrontController.class.php
apps/app_name/lib/myMobileSessionStorage.class.php
apps/app_name/config/factories.yml

memokami::楽天テクノロジーカンファレンス「PHPで作る携帯サイト」 :: handsOut.jp もすごくいい感じ。

コメント:0

コメントフォーム
入力した情報を記憶する

トラックバック:0

この記事のトラックバック URL
http://www.sylvan-l.net/b/2009/02/08/symfony%e3%81%a7%e3%83%a2%e3%83%90%e3%82%a4%e3%83%ab%e9%96%8b%e7%99%ba%e3%81%99%e3%82%8b%e9%9a%9b%e3%81%ab%e5%8f%82%e8%80%83%e3%81%ab%e3%81%aa%e3%82%8b%e3%81%a0%e3%82%8d%e3%81%86%e3%83%aa%e3%83%b3/trackback/
トラックバックの送信元リスト
symfonyでモバイル開発する際に参考になるだろうリンク - sylvan より

ホーム > Web開発関連 > symfonyでモバイル開発する際に参考になるだろうリンク

ぴくちゃー
ブログパーツ

ページの上部に戻る