Cakephp : search by date ,without range -
i new cakephp. how search date in cakephp , without range . pick date using date picker , search. in index part created records there .i have 1 datepicker , search button there in top of index.ctp. in search should write
creating part finished . in creating , if choose date , view means details of particular date should display.
this 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 add new users page --> <script> $(function() { $(".datepicker").datepicker({ dateformat: "yy-mm-dd" }); }); </script> <?php foreach($create $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 $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>
well using formhelper create form using post method. have no idea why want suply id. also, seems expect more 1 user returned should start journey on selected date... in case $user['create']['id'] doesn't make sense.
change this:
<?php echo $this->form->create("create",array('action' => 'search')); ?>
in controller need find users starting journey on selected date: since default formhelper uses post submit method, can find form data in: $this->request->data['mymodel']['title'];
if not sure, can output submitted data with
pr($this->request->data);
your search function should 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 more carefull naming models, since 'create' doesn't seems apropiate in case. out of cakephp should live conventions. http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html
Comments
Post a Comment