【发布时间】:2017-01-02 03:21:21
【问题描述】:
我试图理解 laravel。 在我的测试中,我创建了一个这样的控制器:
public function getDirectorySize( $path = null)
{
$path="/folder/";
$pathlog="/laravel.log";
$pathbackup="/folder/";
$ar=getDirectorySize($path);
$totalsize = 0;
$totalcount = 0;
$dircount = 0;
if ($handle = opendir ($path))
{
while (false !== ($file = readdir($handle)))
{
$nextpath = $path . '/' . $file;
if ($file != '.' && $file != '..' && !is_link ($nextpath))
{
if (is_dir ($nextpath))
{
$dircount++;
$result = getDirectorySize($nextpath);
$totalsize += $result['size'];
$totalcount += $result['count'];
$dircount += $result['dircount'];
}
elseif (is_file ($nextpath))
{
$totalsize += filesize ($nextpath);
$totalcount++;
}
}
}
}
closedir ($handle);
$total['size'] = $totalsize;
$total['count'] = $totalcount;
$total['dircount'] = $dircount;
return $total;
}
在我的刀片中,我想显示这样的数据:
Details for the path : {{ $path }}
Details for the log : {{ $pathlog }}
Details for the backup : {{ $pathbackup }}
Total size : {{ sizeFormat($ar['size']) }}
No. of files : {{ $ar['count'] }}
<? echo "No. of directories : ".$ar['dircount']."<br>"; ?>
但我收到了这个错误:
Undefined variable: path
我想显示这个函数的任何信息
【问题讨论】:
-
您不应该将这些变量发送到视图吗?
-
我想在我的刀片视图中显示 $path :( 任何解决方案?
-
return view('template, ['path' => $path]); -
我已将此添加到我的控制器中:$this->data = array('path' => $path);但仍然无法正常工作