【问题标题】:Function on helper.php not detected with codeception Laravel使用 codeception Laravel 未检测到 helper.php 上的函数
【发布时间】:2015-06-24 15:22:51
【问题描述】:

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

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;
}

我使用此辅助函数进行表单选择,但在运行代码接收时,调用未定义函数 rangeWithKeys() 错误。

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

【问题讨论】:

    标签: php laravel-4 codeception


    【解决方案1】:

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

    use <helper class name>;
    

    【讨论】:

    • 是的,我再次尝试在控制器顶部添加辅助类,但它不起作用。
    • 当我在 codeception 测试文件夹下的 _boostrap.php 中添加 require _DIR_.'/../bootstrap/autoload.php'; 就可以了.
    猜你喜欢
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2017-02-12
    相关资源
    最近更新 更多