Changeset 23661
- Timestamp:
- 11/14/08 17:25:40 (5 years ago)
- Location:
- lang/perl/MENTA/trunk
- Files:
-
- 1 added
- 4 modified
-
NOTE (modified) (1 diff)
-
app/controller/bbs_sqlite.pl (modified) (2 diffs)
-
app/data/data.sqlite (modified) (previous)
-
app/tmpl/bbs.html (modified) (2 diffs)
-
app/tmpl/pager.html (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/MENTA/trunk/NOTE
r23659 r23661 49 49 docroot は環境変数でうまくやれないかな 50 50 uri_for みたいなのがほしい? 51 フックとかつける? 52 redirect/render とかは発行したら detach するべき 51 53 -
lang/perl/MENTA/trunk/app/controller/bbs_sqlite.pl
r23659 r23661 1 1 use DBI; 2 2 3 # DBI ってやっぱりわかりにくいよねえ 3 # DBI ってやっぱりわかりにくいよねえ。もうちょいすっきりこれを書けるプラグインが欲しい。 4 4 5 5 sub do_bbs_sqlite { … … 15 15 redirect(docroot . 'bbs_sqlite'); 16 16 } else { 17 my $sth = $dbh->prepare('SELECT id, body FROM entries ORDER BY id DESC LIMIT 10') or die $dbh->errstr; 18 $sth->execute(); 17 my $page = param('page') || 1; 18 my $limit = 10; # 1ページあたりの表示件数 19 my $offset = ($page-1) * $limit; 20 my $sth = $dbh->prepare('SELECT id, body FROM entries ORDER BY id DESC LIMIT ? OFFSET ?') or die $dbh->errstr; 21 $sth->execute($limit+1, $offset); 19 22 my @res; 20 23 while (my ($id, $body) = $sth->fetchrow_array()) { 21 24 push @res, {id => $id, body => $body}; 22 25 } 23 render("bbs.html", \@res); 26 my $has_next = 0; 27 if (@res == $limit+1) { 28 pop @res; 29 $has_next++; 30 } 31 render("bbs.html", \@res, { page => $page, has_next => $has_next}); 24 32 } 25 33 } -
lang/perl/MENTA/trunk/app/tmpl/bbs.html
r23660 r23661 1 % my $entries = shift;1 % my ($entries, $pager) = @_; 2 2 % my $title = 'SQLite をつかった一行掲示板' 3 3 %=r render_partial('header.html', $title) … … 13 13 % } 14 14 </ul> 15 16 <%=r render_partial('pager.html', $pager) %> 17
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)