mojolicious 引用了一个并不总是定义的 stash 变量 [英] mojolicious referencing a stash variable not always defined

查看:44
本文介绍了mojolicious 引用了一个并不总是定义的 stash 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总的来说,我仍在学习 mojolicious 和 MVC 框架,所以这可能是一个问题,我正在考虑这个错误,所以如果我愿意,请提出更好的方法来执行以下操作.

I am still learning mojolicious and MVC frameworks in general so this just might be a problem where I am thinking about this wrong so if I am please suggest a better way to do the following.

我有一条路线/route/:param 其中 param 有时已定义,有时未定义.我试图在该路由的模板中使用param",但我收到一条错误消息,指出param"需要明确的包名称.我知道这是由于 :param 在路由中不匹配,因为当我调用/route/value 时一切正常.

I have a route /route/:param where param is sometimes defined and sometimes not. I am trying to use "param" in the template for that route but I get an error saying "param" requires explicit package name. I know this is due to :param not matching in the route because when I do call /route/value everything works fine.

当定义和未定义param"时,有没有办法能够对两者使用相同的模板?我只是想根据param"中定义的内容预先填充一个表单,但没有强制要求.

Is there a way to be able to use the same template for both when "param" is defined and not defined? I am just trying to pre-populate a form off of what is defined in "param" but not making it required to.

在我的模板中

<% if(defined($param)){ %><%= $param %><% } %>

谢谢.

推荐答案

引用 stash("param") 总是安全的,其中 stashMojolicious::Plugin::DefaultHelpers 中定义的辅助函数:

It is always safe to refer to stash("param"), where stash is a helper function defined in Mojolicious::Plugin::DefaultHelpers:

<%= stash "param" %>
<%= defined(stash("param")) && stash("param") %>
etc.

这篇关于mojolicious 引用了一个并不总是定义的 stash 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆