嗨我試圖創建一個功能,搜索我的上傳模型,並顯示該表中的信息。CakePHP 2.0搜索數據庫錯誤
Notice (8): Undefined variable: uploads [APP/View/Uploads/search.ctp, line 28]
Warning (2): Invalid argument supplied for foreach() [APP/View/Uploads/search.ctp, line 28]
之前,我甚至允許搜索我得到這個錯誤,
這是我search.ctp
<?php $uploads = $this->requestAction('uploads/search');
?>
<div id="search">
<?php echo $this->Form->create('Upload',array('action'=>'search'));?>
<fieldset>
<legend><?php __('Upload Search');?></legend>
<?php
echo $this->Form->input('searchupload', array('label' => false, 'class'=>'searchinput'));
$options = array(
'label' => '',
'value' => 'Search',
'class' => 'searchbutton'
);
echo $this->Form->end($options);
?>
</fieldset>
</div>
<div id="contentbox">
<table>
<?php foreach($uploads as $upload) : ?>
<tr>
<td><?php echo $upload['Upload']['name'] ?></td>
<td><?php echo $upload['Upload']['eventname'] ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
,這是在上傳控制器的功能:
function search() {
if (!empty($this->data)) {
$searchstr = $this->data['Upload']['search'];
$this->set('searchstring', $this->data['Upload']['search']);
$conditions = array(
'conditions' => array(
'or' => array(
"Upload.name LIKE" => "%$searchstr%",
"Upload.eventname LIKE" => "%$searchstr%"
)
)
);
$this->set('uploads', $this->Upload->find('all', $conditions));
}
}
任何幫助將不勝感激!
在此先感謝
我發現的錯誤之一, '回聲$這個 - >形式 - >輸入(」沒有搜索匹配searchupload',array('label'=> false,'class'=>'searchinput'));'應該搜索而不是searchupload,但是我的foreach會一直顯示錯誤信息直到搜索完成?有沒有辦法擺脫消息? – 001221 2012-04-28 18:32:34