helper.php上没有检测到的功能Laravel

问题描述:

我正在使用Codeception对我的laravel(4)项目进行功能测试。但它没有在Laravel helper.php文件中检测到函数定义。如果有人知道,请让我知道如何解决它。谢谢。helper.php上没有检测到的功能Laravel

function rangeWithKeys($from, $to, $leadingZeros = false) 
{ 

    if ($leadingZeros === TRUE) 
    { 
     $array = []; 

     for($i =$from; $i <= $to; $i++) 
     { 
      if($i<10){ 
       $prefixedNumber = '0'.$i; 
       $array[$prefixedNumber] = $prefixedNumber; 
      }else{ 
       $array[$i] = $i; 
      } 
     } 

     return $array; 

    } 

    $array = array_combine(range($from,$to),range($from,$to)); 

    return $array; 
} 

我用这个辅助函数的形式选择,但运行时codeception,得到了调用未定义功能rangeWithKeys()错误。

{{ Form::select('birthMonth', array('M' => 'M') + rangeWithKeys(1,12, TRUE), Input::old('Month') ? Input::old('Month') : 'M',['class' => 'form-control'])}} 

您可以在控制器文件的顶部包含以下语法。

use <helper class name>; 
+0

是的,我再次尝试在控制器顶部添加辅助类,但它不起作用。 –

+0

当我在codeception测试文件夹下的_boostrap.php中添加** require __DIR __。'/ ../bootstrap/autoload.php'; **时, –