Subscribe to RSS Feed

Subscribe to Comments Feed

Subscribe to Atom Feed

tech

技術的なことのメモ
  • blog
  • sitemap
  • 紹介

paginatorのSmarty化

by outsider タグ: cakephp, php
07 08 2009

無理やりですが。
対象のテーブルはServersとします。

  • smarty.phpの修正
  • [cakeのインストール先]/app/views/smarty.phpの69行目あたりにtemplate_dirの定義を追加。

    $this->smarty->cache_dir = TMP.'smarty'.DS.'cache'.DS;
    $this->smarty->template_dir = dirname(__FILE__);  # これを追加
    $this->smarty->error_reporting = 'E_ALL & ~E_NOTICE';
  • layoutファイルの修正
  • [cakeのインストール先]/app/views/layouts/smarty/default.tplを修正。

    <!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">
    <head>
    {$html->charset()}
    <title>{$title_for_layout}</title>
    {$html->meta('icon')}
    {$html->css('cake.generic')}
    {$scripts_for_layout}
    </head>
    <body>
    {$content_for_layout}
    </body>
    </html>
  • paging.tplの作成
  • [cakeのインストール先]/app/views/elements/にpaging.tplを作成。

    {assign_assoc var='CounterArray' value='format=>全%pages%ページ中の%page%ページ目を表示中  全%count%件中の%start%件目から%end%件目の%current%件を表示中'}
    {$paginator->counter($CounterArray)}
    </p>
    <table cellpadding="0" cellspacing="0" border="1">
    <tr>
     {foreach from=$paging_data.0.$model key=key item=head}
     <th>{$paginator->sort($translate.$key,$key)}</th>
     {/foreach}
     <th>Actions</th>
    </tr>
    {foreach from=$paging_data item=data}
     <traltrow,altrow2"}">
    
     {foreach from=$data.$model key=key item=item}
     <td>
     {$item}<br>
     </td>
     {/foreach}
     {assign var='id' value=$data.$model.id}
     {assign_assoc var='view_link' value='action=>view,$id'}
     <td>
     {$view_link}
     {$html->link('View', "view/$id")}
     {$html->link('Edit', "edit/$id")}
     {$html->link('Delete', "delete/$id")}
     </td>
     </tr>
    {/foreach}
    </table>
    </div>
    <div>
     {$paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'))}
     |      {$paginator->numbers()}
     {$paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'))}
    </div>
  • 翻訳テーブルの作成
  • 例えば

    create table translates (
            id              serial NOT NULL,
            word            text,
            translate       text,
            created         timestamp(0) default NULL,
            modified        timestamp(0) default NULL
    );
    

    こんな感じで。対象のテーブルの各項目をwordに、その訳をtranslateに格納しておきます。

  • controllerの修正
  • translatesテーブルを使う。

    var $uses = array('Servers','Translates')
    

    index functionの中を修正。

    function index() {
       $this->Server->recursive = 0;
      //$this->set('servers', $this->paginate());
    
       $this->set(
           'translate',$this->Translate->find(
                'list',
                array('fields'=>
                      array('Translate.word','Translate.translate')
                )
            )
        );
    
        $this->set('model','Server');
        $this->set('paging_data', $this->paginate());
     }
  • viewの変更
  • index.ctpの代わりにindex.tplを作成。

    <div>
    <h2>{$model}</h2>
    <p>
    {include file="elements/paging.tpl"}

    Related posts:

    1. bakeで雛型を作る

    0 comments
    add to hatena hatena.comment (0) add to del.icio.us (0) add to livedoor.clip (0) add to Yahoo!Bookmark (0) Total: 0

    Leave a Reply

    返信をキャンセル

    google adsense

    カテゴリー

    • CentOS
    • php
      • cakephp
    • Windows
    • wordpress

    タグ

    cakephp CentOS munin php Windows wordpress yum
    Design by: Bingo - The Web Design Experts