Reputation: 3
I am new to cakephp. How to search by date in cakephp , without range . pick a date using date picker and search. In my index part created records are there .I have one datepicker and search button is there in top of index.ctp. In search what should i write
Creating part finished . In that creating , if i choose a date and view means the details of the particular date should display.
This is my coding
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>
Upvotes: 0
Views: 853
Reputation: 1638
Well using the FormHelper like that will create a Form using the POST method. I have no idea why you would want to suply it with an id. Also, it seems like you expect more then one user to be returned that should start their journey on the selected date... in that case $user['Create']['id'] doesn't make any sense.
change it to this:
<?php echo $this->form->create("Create",array('action' => 'search')); ?>
In your controller you need to find all the users starting their journey on the selected date: Since by default the FormHelper uses POST as submit method, you can find the form data in: $this->request->data['MyModel']['title'];
if your not sure, you can always output the submitted data with
pr($this->request->data);
Your search function should look like:
public function Search(){
$date = $this->request->data['Create']['date'];
$user = $this->Create->find('all', array(
'conditions' => array(
'journeydate'=> $date,
),
));
$this->set('create', $user);
}
You should also be more carefull with naming your models, since 'Create' doesn't seems very apropiate in this case. To get the most out of CakePHP you should live by the conventions. http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html
Upvotes: 1