私はコンピュータテーブルを持つSQLiteデータベースを持っています。私はコンピュータのテーブルに2つの行があります。リクエストの結果がテンプレートツールキットに表示されない
すべてのコンピュータを取得し、結果をテンプレートツールキットテンプレートで表示したいと考えています。
これは Dancer2::Plugin::Auth::Tiny
と Dancer2::Plugin::DBIC
get '/listallmachine' => needs login => sub {
my $computerRs = schema('default')->resultset('Computer');
my @computers = $computerRs->all;
template 'listmachine' => {
'title' => 'Liste des machines',
'msg' => get_flash(),
'computers' => \@computers
};
};
そして、テンプレート用を使用しています Dancer2
コントローラコード、次のとおりです。
[% FOREACH c IN computers %]
<tr>
<td>[% c.ip %]</td>
<td>[% c.uuid %]</td>
</tr>
[% END %]
設定ファイル:
# configuration file for development environment
# the logger engine to use
# console: log messages to STDOUT (your console where you started the
# application server)
# file: log message to a file in log/
logger: "console"
# the log level for this environment
# core is the lowest, it shows Dancer2's core log messages as well as yours
# (debug, info, warning and error)
log: "core"
# should Dancer2 consider warnings as critical errors?
warnings: 1
# should Dancer2 show a stacktrace when an 5xx error is caught?
# if set to yes, public/500.html will be ignored and either
# views/500.tt, 'error_template' template, or a default error template will be used.
show_errors: 1
# print the banner
startup_info: 1
plugins:
DBIC:
default:
dsn: dbi:SQLite:dbname=papt.db
テンプレートには何も表示されません。何かお考えですか?
'@ computers'の内容を確認しましたか? – Borodin
はいこれは自分のコンピュータデータです:要求の結果。私がテンプレートを使用しない場合、それは仕事です... – Oneill
私の答え(下記)が助けになると思ったが、ここではもっと進んでいるようだ。 Template Toolkitを削除してPerlコードで配列をループするだけでどうなりますか?テンプレートに '[%computers.size%]'を含めるとどうなりますか?または '[%computers.0%]'? –