我有以下功能:
# Get Directories of Path as Array
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
$result[] = $value;
}
}
}
return $result;
}
并将其称为:
$watchFolder = 'C:\\xampp\\htdocs\\project\\One\\';
$this->dirToArray($watchFolder);
但我得到以下错误:
调用未定义的函数App \ Http \ Controllers \ dirToArray()
有谁知道如何解决这个问题?
编辑: 所以我的完整控制器看起来像这样:
<?php
namespace App\Http\Controllers;
use DB;
use Mail;
use File;
use Input;
use Request;
use Illuminate\Filesystem\Filesystem;
use App\Http\Controllers\Controller;
class ProductRController extends Controller
{
public function createProduct()
{
...
$watchFolder = 'C:\\xampp\\htdocs\\Product\\R\\';
$this->dirToArray($watchFolder);
return redirect()->route('root')->with('message', 'Success')->withInput();
}
else
{
return redirect()->route('newProduct')->with('message', 'Error')->withInput();
}
}
# Get Directories of Path as Array
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
$result[] = $value;
}
}
}
return $result;
}
}
答案 0 :(得分:0)
您仍然需要在函数内部使用ng-disabled="secondStep.$invalid"
,因为$this->
表示您在其上调用方法的对象:
$this