0

跟随 mojocasts 第 2 集学习 mojolicious。

我有这个例子

#!/usr/bin/env perl
use Mojolicious::Lite;

get '/:fname/:lname' => sub {
    shift->render('hello');
};

app->start;

__DATA__

@@ hello.html.ep
<!doctype html><html>
    <head><title>Placeholders</title></head>
    <body><i>Hello <%= fname %> <%= $lname %></li></body>
</html>

但是,当我转到该地址时,http://127.0.0.1:3000/sayth/renshaw我从服务器收到此错误。

[Fri Apr 25 15:59:05 2014] [error] Bareword "fname" not allowed while "strict subs" in use at template hello.html.ep from DATA section line 3, <DATA> line 17.
1: <!doctype html><html>
2:     <head><title>Placeholders</title></head>
3:     <body><i>Hello <%= fname %> <%= $lname %></li></body>
4: </html>

我不相信我已经指定了严格的潜艇,我该如何解决这个问题?

编辑:我正在运行 curl 安装的最新版本,并安装了 perl 5.16.3。

4

1 回答 1

3

Mojolicioususe strict;默认启用。心怀感激 :)

该错误与您在 perl 代码中得到的错误相同:

Bareword "fname" not allowed while "strict subs" in use at template hello.html.ep

基本上,您之前只是缺少一个美元符号fname

@@ hello.html.ep
<!doctype html><html>
    <head><title>Placeholders</title></head>
    <body><i>Hello <%= $fname %> <%= $lname %></li></body>
</html>

或者您也可以使用这种格式:

@@ hello.html.ep
<!doctype html><html>
    <head><title>Placeholders</title></head>
    <body><i>Hello <%= param('fname') %> <%= param('lname') %></li></body>
</html>
于 2014-04-25T06:26:42.520 回答