2015-11-18 22:45
浏览 45


I'm trying to write a view helper that calls other helpers dynamically, and I am have trouble passing more than one argument. The following scenario will work:

$helperName = "foo";
$args = "apples";

$helperResult = $this->view->$helperName($args);

However, I want to do something like this:

$helperName = "bar";
$args = "apples, bananas, oranges";

$helperResult = $this->view->$helperName($args);

with this:

class bar extends AbstractHelper
    public function __invoke($arg1, $arg2, $arg) 

but it passes "apples, bananas, oranges" to $arg1 and nothing to the other arguments.

I don't want to have to send multiple arguments when I call the helper because different helpers take different numbers of arguments. I don't want to write my helpers to take arguments as an array because code throughout the rest of the project calls the helpers with discreet arguments.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试编写一个动态调用其他助手的视图助手,而且我在传递多个助手时遇到问题 论点。 以下方案将起作用:

  $ helperName =“foo”; 
 $ args =“apples”; 
 $ helperResult = $ this-> view-  > $ helperName($ args); 


   $ helperName =“bar”; 
 $ args =“apples,bananas,oranges”; 
 $ helperResult = $ this-> view-> $ helperName($ args); 
  <  / pre> 


公共函数__invoke($ arg1,$ arg2,$ arg)\  n {

但它将“apple,bananas,oranges”传递给 $ arg1 并且没有其他参数。

我不想在调用助手时发送多个参数,因为不同的助手会使用不同数量的参数。 我不想编写我的帮助程序来将参数作为数组,因为整个项目的其余部分的代码都使用谨慎的参数调用帮助程序。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题