我是cakephp的新手。 如何在cakephp中按日期搜索,無範圍。 使用日期選擇器和搜索選擇一個日期。 在我的索引部分創建的記錄在那裏。我有一個日期選擇器和搜索按鈕是在index.ctp的頂部。 在搜索我應該寫什麼Cakephp:按日期搜索,無範圍
創建部分完成。在那個創建中,如果我選擇日期和視圖意味着特定日期的細節應該顯示。
這是我使用這樣的表單助手井將創建一個使用POST方法的表單的編碼
function index()
{
$user = $this->Create->find('all');
$this->set('create', $user);
}
function Search()
{
???
$user = $this->Create->find('all',array('conditions'=>array('journeydate'=>'journeydate')));
$this->set('create', $user);
}
index.ctp
<!-- link to add new users page -->
<script>
$(function() {
$(".datepicker").datepicker({ dateFormat: "yy-mm-dd" });
});
</script>
<?php
foreach($create as $user){}
?>
<?php echo $this->form->create("Create",array('action' => 'search',',$user['Create']['id']));
echo $this->form->input('date',
array(
'class'=>'datepicker',
'type'=>'text'
));
echo $this->form->end("Search");
?>
<table style='padding:5px;'>
<!-- table heading -->
<tr style='background-color:#fff;'>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Phone no</th>
<th>Bus Name</th>
<th>Ticket no</th>
<th>Seat No</th>
<th>From</th>
<th>To</th>
<th>Journey Date</th>
<th>Booking Date</th>
<th>Amount</th>
</tr>
<?php
foreach($create as $user){
echo "<tr>";
echo "<td>{$user['Create']['id']}</td>";
echo "<td>{$user['Create']['name']}</td>";
echo "<td>{$user['Create']['age']}</td>";
echo "<td>{$user['Create']['gender']}</td>";
echo "<td>{$user['Create']['phoneno']}</td>";
echo "<td>{$user['Create']['busname']}</td>";
echo "<td>{$user['Create']['ticketno']}</td>";
echo "<td>{$user['Create']['seatno']}</td>";
echo "<td>{$user['Create']['from']}</td>";
echo "<td>{$user['Create']['to']}</td>";
echo "<td>{$user['Create']['journeydate']}</td>";
echo "<td>{$user['Create']['bookingdate']}</td>";
echo "<td>{$user['Create']['amount']}</td>";
echo "</tr>";
}
?>
<tr><td>
<INPUT TYPE="BUTTON" VALUE="Back" ONCLICK="window.location.href='/newcake/creates/create'"></td></tr>
</table>
請發佈您試過的代碼,我們可以幫助您改進或修復它。即使你編寫僞代碼是一個開始,但目前,你的問題基本上聽起來像「請給我寫我的控制器的動作」 – Dave