【发布时间】:2020-05-18 12:38:43
【问题描述】:
我目前面临一个小问题。让我解释 : 我在cakphp 2.9下开发数据库我使用自定义搜索功能,问题是点击下一页时出现错误(第一页显示无忧) 这是我的控制器页面:UsersController.php
public function search_club()
{
if (!empty($this->request->data)) {
$info1 = trim($this->request->data['Joueur']['CLUB']);
//debug($info1); die();
$joueurs = $this->Joueur->find('all', [
'conditions' => [
'AND' => [
'LOWER(Joueur.CLUB) LIKE' => '%' . strtolower($info1) . '%',
'Joueur.STATU' => '1'
]
]
]);
//debug($joueurs); die();
$this->Joueur->recursive = 0;
$this->paginate = [
'limit' => 20,
'conditions' => [
'and' => [
'Joueur.STATU' => '1',
'LOWER(Joueur.CLUB) LIKE' => '%' . strtolower($info1) . '%'
]
]
];
$joueurs = $this->paginate('Joueur');
$this->set('joueurs', $joueurs);
}
}
这是我的视图文件
<?php
$paginator = $this->Paginator;
foreach ($joueurs as $joueur):
echo'<tbody>';
echo'<tr>';
echo '<td class="hidden-480">
<center>';
echo $joueur['Joueur']['LICENCES'];
echo'</center>
</td> ';
echo '<td class="hidden-480">
<center>';
echo $joueur['Joueur']['NOM'];
echo'</center>
</td> ';
echo '<td class="hidden-480">
<center>';
echo $joueur['Joueur']['PRENOM'];
echo'</center>
</td> ';
echo '<td class="hidden-480">
<center>';
echo $joueur['Joueur']['CLUB'];
echo'</center>
</td> ';
echo'<td>
<center>';
echo $joueur['Joueur']['SEXE'];
echo'</center>
</td>';
echo'<td>
<center>';
echo $joueur['Joueur']['NATIONALITE'];
echo'</center>
</td>';
echo'<td>
<center>';
echo $joueur['Joueur']['PROVEN'];
echo'</center>
</td>';
echo'<td>
<center>
<i class="ace-icon fa fa-eye-o"> </i>';
echo $this->Html->link('Modifier/Voir',
array('controller' => 'users', 'action' => 'edit_play', $joueur['Joueur']['id']),array('target' => '_blank'));
echo'</center>
</td>';
echo '<td class="hidden-480">
<center>';
echo $this->Form->postLink(__('Supprimer'), array('action' => 'delet_play', $joueur['Joueur']['id']), null, __('Etes vous sûr de vouloir supprimé cet élément ?', $joueur['Joueur']['PRENOM']));
echo'</center>
</td>
</tr>
</tbody>';
endforeach;
unset($joueur);
echo'</table>
</div>
</div>
</div>
</div>';
echo'
<div style="height:50px!important">
</div>';
// pagination section
echo "<div class='paging' style='text-align:center'>";
// the 'first' page button
echo $paginator->first("Debut");
// 'prev' page button,
// we can check using the paginator hasPrev() method if there's a previous page
// save with the 'next' page button
if($paginator->hasPrev()){
echo $paginator->prev("Precedent");
}
// the 'number' page buttons
echo $paginator->numbers(array('modulus' => 3));
// for the 'next' button
if($paginator->hasNext()){
echo $paginator->next("Suivant");
}
// the 'last' page button
echo $paginator->last("Fin");
echo "</div>";("Fin");
echo" </div>
</div>";
?>
</div>
现在这是我点击下一页时遇到的错误
注意(8):未定义变量:joueurs [APP/View/Elements/resume_search_club.ctp,第 174 行]
警告 (2):为 foreach() 提供的参数无效 [APP/View/Elements/resume_search_club.ctp,第 174 行]
几天来我一直在寻找解决方案,所以我真的需要你的帮助
提前致谢
【问题讨论】:
-
请贴出完整的控制器方法代码,不要剪掉(可能半途而废)。还要尝试正确格式化/缩进它,这有助于发现流量控制问题。
-
这是完整的控制器方法代码,我只是忘记添加这些函数的末尾,我现在将更新......
标签: cakephp cakephp-2.9