我需要在自定义帮助程序或指令中获取从控制器传递的所有视图数据,在此视图刀片模板中调用。所以在刀片模板中有翻译:@lang($periodName . '.H1 title', ['time' => $time])我想让它更短。为此,我创建了 helper periodTrans ('H1 Title')。function periodTrans($title) { return __($periodName . '.' . $title, ['time' => $time]);}有没有办法在辅助函数中访问$periodName和$time变量,而不是像参数一样传递它们并使函数更短?
1 回答
慕仙森
TA贡献1827条经验 获得超8个赞
AFAIK 这应该有效。
在您的controller:
public function __construct()
{
.....
\View::share('periodName', $periodName);
\View::share('time', $time);
}
你的帮手:
function periodTrans($title) {
$data = \View::getShared();
return __($data['periodName'] . '.' . $title, ['time' => $data['time']]);
}
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消