我有一個帶有計算機表的SQLite數據庫。我在電腦桌上有兩排。請求的結果不顯示在模板工具包中
我想要得到所有電腦,並在模板工具包模板中顯示結果。
這是 Dancer2
控制器代碼,它使用 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
};
};
而對於模板:
[% 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
好的。我認爲我的答案(如下)會有所幫助,但似乎還有更多的事情在這裏進行。如果您消除了模板工具包並在Perl代碼中循環訪問數組,那麼會發生什麼?如果在模板中包含'[%computers.size%]',你會得到什麼?或'[%computers.0%]'? –