symfonyでモバイル開発する際に参考になるだろうリンク
http://blog.handsout.jp/player/721
モバイル開発@symfony :: handsOut.jp がかなり良い感じ。以下コードを引用してみる。
apps/app_name/config/filters.yml [code] rendering: ~ web_debug: ~ security: ~
generally, you will want to insert your own filters here
mobile: class: myMobileFilter cache: ~ common: ~ flash: ~ execution: ~ [/code]
apps/app_name/config/autoload.yml [code] autoload: PEAR: name: PEAR files: Net_UserAgent_Mobile: /path/to/Net/UserAgent/Mobile.php [/code]
myMobileFilter.class.php (抜粋) [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, 'utf8'); $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); } [/php]
apps/app_name/templates/layout.php (抜粋) [php]
[/php]
apps/app_name/templates/_dtd.php [php] getRequest()>getAttribute('carrier')): ?> <?php echo '?xml version="1.0" encoding="Shift_JIS" ?>
<?php echo '?xml version="1.0" encoding="Shift_JIS" ?>
// 以下略 [/php]
他にも 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 もすごくいい感じ。