zend框架中的用户定义函数

时间:2012-01-20 06:19:00

标签: php zend-framework

这段代码与普通的php一起工作正常:

<?php
function barber($type)
{
    echo "You wanted a $type haircut, no problem\n";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>

如何在Zend控制器的Action中实现相同的东西? (我相信Zend不会允许在引号中调用函数而 $ this self 在这件事上是不可能的)

1 个答案:

答案 0 :(得分:4)

在控制器中创建一个方法,例如

private function foo($var) {
    return $var++;
}

使用call_user_func()

这样称呼它
call_user_func(array($this, 'foo'), $a);
相关问题