我是 Yii 的新手,我在将数组从控制器中的操作传递到视图时遇到问题,以便我可以在视图本身中读取数组的内容。
我的控制器:
public function actionReportAllWeeks()
{
$user = YumUser::getById(Yii::app()->user->id);
$format = 'Y-m-d';
$clients = Client::model()->findAll();
$UNI = array();$NPP = array();$DAN = array();$McC = array();$CAS = array();$LAC = array();
foreach ($clients as $client) {
$project_count = 0;
$projects = Project::model()->findAll(array('condition'=>'client_id='.$client->id));
for ($i=1; $i < 30; $i++) {
foreach ($projects as $project) {
$date_created = $project->created;
$createdDate = DateTime::createFromFormat($format, $date_created);
$week_num = $createdDate->format('W');
if ($client->shortname == 'UNI') {
if ($week_num == $i) {
$UNI[$i]++;
}
}
elseif ($client->shortname == 'NPP') {
if ($week_num == $i) {
$NPP[$i]++;
}
}
elseif ($client->shortname == 'DAN') {
if ($week_num == $i) {
$DAN[$i]++;
}
}
elseif ($client->shortname == 'McC') {
if ($week_num == $i) {
$McC[$i]++;
}
}
elseif ($client->shortname == 'CAS') {
if ($week_num == $i) {
$CAS[$i]++;
}
}
elseif ($client->shortname == '') {
if ($week_num == $i) {
$LAC[$i]++;
}
}
}
}
}
$this->render('client/client', array('clients'=>$clients, 'UNI'=>$UNI, 'NPP'=>$NPP, 'DAN'=>$DAN, 'McC'=>$McC, 'CAS'=>$CAS, 'LAC'=>$LAC));
}
我的观点:
<table class="table table-striped table table-bordered" style="width:95%">
<thead>
<tr>
<th>Projects</th>
<?php for ($i=1; $i < 52; $i++):?>
<td style="text-align:center">Week <?php echo $i; ?></td>
<?php endfor; ?>
</tr>
</thead>
<tbody>
<?php foreach ($clients as $client): ?>
<tr>
<td><?php echo $client->name; ?></td>
<?php for ($i=1; $i < 52; $i++):?>
<td style="text-align:center">/*should echo some values from array*/</td>
<?php endfor; ?>
</tr>
<?php endforeach;?>
</tbody>
当我尝试从任何数组中读取元素时,我得到“未定义的偏移量 1”错误。