array_map无法在Bootstrap中找到函数

时间:2011-05-02 16:33:30

标签: zend-framework function array-map

我在Bootstrap文件中创建了一个函数,我想用 array_map 函数调用它。 但它告诉我这个错误:

Warning: array_map() expects parameter 1 to be a valid callback, function 'rootCreator' not found or invalid function name in ...

这是我调用array_map的代码:

$controls = array('products','productsubcat','newssubcat');
array_map('rootCreator', $controls);

这是我的功能代码:

public function rootCreator($cotroller)
{
    $frontController = Zend_Controller_Front::getInstance();
    $defaults = array('module'=>'default' ,'controller'=> $cotroller , 'action'=>'info' );
    $productRoute = new Zend_Controller_Router_Route($cotroller . '/:id/:title', $defaults);
    $router = $frontController->getRouter();
    $router->addRoute($cotroller, $productRoute);
}

1 个答案:

答案 0 :(得分:5)

如果您的函数是对象的方法,则还需要传递对象。

尝试

array_map(array($this, 'rootCreator'), $controls);

如果它不在同一个对象上,则需要传递一个实例。对于静态方法,您可以传递类名。