我试图理解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
我想显示此功能的任何信息
答案 0 :(得分:0)
你能尝试这样的事吗?
public function yourControllerFunction() {
$path="/folder/";
$pathlog="/laravel.log";
...
// Add variables you want to pass to the view
$data = array(
'path' => $path,
'pathlog' => $pathlog,
)
return view('view_file', $data);
}
然后在视图中,您应该能够访问$ path和$ pathlog。