【发布时间】:2018-09-22 19:34:42
【问题描述】:
我有一个显示不同数据样本的工作类文件、控制器和视图,但我目前正在添加一个新函数,该函数从数据库中获取数据,将其传递给控制器并定义它,然后将其传递给刀片/视图。
我并没有真正做任何与其他功能不同的事情,但数据没有显示在我的刀片中。占位符在网页上的间距适当,但数据不显示。查询正在获取结果,并且函数正在传递给刀片,因为 foreach 正在创建额外的行。我在想我对刀片中的变量使用了不正确的语法,这就是我的数据实际上没有显示的原因。
任何帮助在这里表示赞赏:
EMPLOYEE.php
class employeeCalls
{
public function __construct()
{
$this->yyyy = date('Y');
$this->pyyy = $this->yyyy - 1;
$this->from = "{$this->pyyy}-01-01";
$this->through = $this->pyyy . '-' . date('m-d');
$this->fullYear = "{$this->pyyy}-12-31";
$this->newFrom = "{$this->yyyy}-01-01";
$this->newThrough = date('Y-m-d');
}
public function sample($employee)
{
$employee = (int) $employee;
$from = $this->from;
$through = $this->through;
$newFrom = $this->newFrom;
$newThrough = $this->newThrough;
$FullYear = $this->fullYear;
$sql = "
select employee, 'PRIOR' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$from}' and '{$through}'
group by employee
union all
select employee, 'CURRENT' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$newFrom}' and '{$newThrough}'
group by employee
union ALL
select employee, 'FULL' as Range, count(*) as count
from empCalls
where employee = {$employee}
AND fordate between '{$from}' and '{$FullYear}'
group by employee
";
return Connection::runQuery($sql);
}
}
EmployeeController.php
$employeeCalls = new employeeCalls();
$samples = $employeeCalls->sample($this->slsno);
return view('Employee.index')
->with('slsno', $this->slsno)
->with('samples', $samples);
}
blade.php
<div class="md-card-content">
@foreach($samples as $sample)
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['PRIOR'] }}</span></div>
<span class="uk-text-muted uk-text-medium">2017 YTD</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['CURRENT'] }}</span></div>
<span class="uk-text-muted uk-text-medium">2018 YTD</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
<div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['FULL'] }}</span></div>
<span class="uk-text-muted uk-text-medium">2017 Full Year</span>
<div class="clearfix"></div>
<div class="clearfix"></div>
<hr />
@endforeach
</div>
更新:
这是从 $samples 转储的内容
array:3 [▼
0 => array:3 [▼
"employee" => "495"
"RANGE" => "PRIOR"
"COUNT" => "119"
]
1 => array:3 [▼
"employee" => "495"
"RANGE" => "CURRENT"
"COUNT" => "68"
]
2 => array:3 [▼
"employee" => "495"
"RANGE" => "FULL"
"COUNT" => "440"
]
]
【问题讨论】:
-
把$samples里的东西都倒出来,有什么东西吗?
-
很难说。目前还不清楚
Connection::runQuery做了什么或返回了什么。你为什么要像这样绕过 Laravel 的所有模型和数据库功能来调用你自己的数据库? -
@Andrew 我在刀片上做了一个 dd 预期值,发布在我的更新中
-
所以它有数据??你检查过页面吗?也许 md-card-content 被隐藏了??
-
您的刀片模板命名是否正确? .blade.php