アーカイブ

2008 年 8 月 のアーカイブ

symfonyで携帯用にShift_JISで出力する方法

2008 年 8 月 19 日 コメントはありません

いろいろと掲載されてはいましたが、結局うまく行かず、悩んでおりましたが、ようやくできました。

  • apps/(appname)/config/view.ymlを以下のようにcontent-typeを変更
    1
    2
    3
    
    default:
      http_metas:
        content-type: text/html; charset=Shift_JIS
  • apps/(appname)/config/filters.ymlを以下のように変更
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    rendering: ~
    web_debug: ~
    security: ~
    MobileFilter:
      class: MobileFilter
    cache: ~
    common: ~
    flash: ~
    execution: ~
  • 最後に、lib/filters/MobileFilter.phpを作成する。
    コードはべたべたなので、綺麗に書いてくださいね。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    
    <?php
    class MobileFilter extends sfFilter{
      public function execute($filterChain = null){
        if ($this->isFirstCall()){
          //error
          $er=error_reporting();
          if ($er > E_STRICT){
            error_reporting($er - E_STRICT );
          }
          require_once ('Net/UserAgent/Mobile.php');
          $userAgent=Net_UserAgent_Mobile::singleton();
          $this->getContext()->getRequest()->setAttribute('userAgent', $userAgent);
     
          //出力文字コードの制御
    //      sfConfig::set('sf_charset',"shift_jis");
          sfConfig::set('sf_charset',"UTF-8");
          $this->encodingParams('SJIS-win','UTF-8');
     
          mb_internal_encoding('UTF-8');
          //mb_http_output('SJIS-win');
        //  ob_start('mb_output_handler');
        ob_start( array($this,'m_output_handler'));
        }
        if ($filterChain) $filterChain->execute();
      }
      function m_output_handler($buffer){
          sfConfig::set('sf_charset',"shift_jis");
        error_log($buffer,3,"/var/www/morenavi/log/mobile.log");
        return mb_convert_encoding($buffer,'SJIS-win','UTF-8');
        //return $buffer;
      }
     
      protected function encodingParams($from,$to){
        if ($to !='' && $from !='' && $from != $to ){
          $params=$this->getContext()->getRequest()->getParameterHolder()->getNames();
          foreach ($params as $param){
            $in=$this->getContext()->getRequest()->getParameter($param);
            $this->getContext()->getRequest()->setParameter($param, mb_convert_encoding($in,$to,$from));
          }
        }
      }
    }
カテゴリー: 未分類 タグ: , ,

vim: expandtabとか、vim: softtabstopが使えないなぁ!という時

2008 年 8 月 19 日 コメントはありません

vimでソースの頭によく

 /* vim: set expandtab tabstop=2 softtabstop=2 shiftwidth=2 foldmethod=marker enc=utf-8 : */

こう書きますが、どうも設定が反映されていない!ということでよくよく調べたら
http://nanasi.jp/articles/howto/file/modeline.html
で、
そもそも、このモードラインを

set modeline

で、有効にしておかないと使えないということが判明しました。
なんでデフォルトでは使えないのかなぁ。

カテゴリー: 未分類 タグ:

schema.ymlでのforeign_keyの書き方

2008 年 8 月 10 日 コメントはありません

いろいろと調べた上で、ようやくたどり着いたのですが、
通常、symfonyのpropelを利用している場合に、schema.ymlにてforeign_keyを設定したい場合は、

propel:
  blog_article:
    id:
    title:       varchar(255)
    content:     longvarchar
    created_at:
  blog_comment:
    id:
    article_id:
    author:      varchar(255)
    content:     longvarchar
    created_at:

のように、example_id:
だけ設定すれば、exampleテーブルへのforeignKeyを張ってくれるが、そう銘銘できない場合があって、どうするのか、悩んだ末の発見です。

 article:
   id:
   example1_id: { type: integer }
   _foreignKeys:
     fk_1:
       foreignTable: example2
       references:
         -
           foreign: id
           local: example1_id

なんと、foreign_table: ではなく、_foreign_keys:でもありません。ご注意下さい。

カテゴリー: 未分類 タグ:

dwPrototypeWindowPluginでエラー発生

2008 年 8 月 6 日 コメントはありません

dwPrototypeWindowPluginでエラーが発生した。どうやら、prototype1.5.1からprototype.Browserというものがあるらしい。で困ったところ、Prototype.BrowserFeaturesにすればよいみたい。
Prototype.Browser ⇒ Prototype.BrowserFeatures
これでエラーが出なくなりました。

ところが、それでもうまくいきません….。
(もしかしたら、下記のsfPrototypePluginを入れたらよかったのかもしれません)

というところで、sfModalBoxPluginを発見。実は、これは便利!
インストールは、

$ symfony plugin-install http:⁄⁄plugins.symfony-project.com/sfPrototypePlugin
$ symfony plugin-install http:⁄⁄plugins.symfony-project.com/sfModalBoxPlugin

templateにて、

<?php use_helper('ModalBox') ?>
<?php echo m_link_to('モーダル', 'module/action') ?>

でいけてしまいました。

カテゴリー: 未分類 タグ: ,