Laravel Blade回声
Laravel Blade Echo
我正在努力理解 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;
}
在我的 blade 中,我想显示这样的数据:
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
我想显示来自这个函数的任何信息
你能试试这样的吗?
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。
我正在努力理解 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;
}
在我的 blade 中,我想显示这样的数据:
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
我想显示来自这个函数的任何信息
你能试试这样的吗?
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。