I am new for CakePHP. Now I'm having a task which is self-learning where I want to display all the data from PhpMyAdmin between 2 selected dates when user click 'Show' and display at the same page which is "index.ctp".
However, I'm stuck where I do now know where should I put the codes that can display all the information. Below are the codes I had done till now:
Model (room.php):
<?php
class Room extends AppModel{
public $validate = array(
'sdate' => array(
'date' => array(
//Add 'ymd' to the rule.
'rule' => array('date', 'ymd'),
'message' => 'Please select a valid start date.',
),
),
);
'edate' => array(
'date' => array(
//Add 'ymd' to the rule.
'rule' => array('date', 'ymd'),
'message' => 'Please select a valid end date.',
),
),
);
}
Controller (RoomController.php):
<?php
class RoomsController extends AppController{
public $helpers = array('Html', 'Form');
public $components = array('Session');
public function index() {
}
}
?>
index.ctp
<h1>Room Reservation<h1>
<table>
<?php
echo $this->Form->create('rooms',
array(
'type' => 'get'
)
);
echo $this->Form->input('Start Date:',
array(
'label' => 'Start Date',
'id' => 'sdate'
)
);
echo $this->Form->input('End Date:',
array(
'label' => 'End Date',
'id' => 'edate'
)
);
echo $this->Form->end('Show');
?>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#sdate').Zebra_DatePicker();
$('#edate').Zebra_DatePicker();
});
</script>
room_type(Database):
CREATE TABLE `room_type` (
`room_id` int(11) NOT NULL AUTO_INCREMENT,
`room_type` varchar(10) NOT NULL,
`no_of_room` int(10) NOT NULL,
PRIMARY KEY (`room_id`)
);
room_id | room_type | no_of_room
1 | A | 10
2 | B | 10
3 | C | 10
4 | D | 10
room_type_availability(Database):
CREATE TABLE `room_type_availability` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`room_id` int(11) NOT NULL,
`trx_date` date NOT NULL,
`no_of_room` int(2) NOT NULL,
PRIMARY KEY (`id`), ADD KEY `room_id` (`room_id`),
CONSTRAINT `room_type_availability_ibfk_1` FOREIGN KEY (`room_id`) REFERENCES `room_type` (`room_id`) ON DELETE CASCADE ON UPDATE CASCADE
);
id | room_id | trx_date | no_of_room
1 | 1 |2015-05-05 | 10
2 | 1 |2015-05-06 | 10
3 | 1 |2015-05-07 | 9
4 | 1 |2015-05-08 | 7
5 | 1 |2015-05-09 | 6
6 | 2 |2015-05-05 | 8
7 | 2 |2015-05-06 | 3
8 | 2 |2015-05-07 | 6
9 | 2 |2015-05-08 | 4
10 | 2 |2015-05-09 | 5
If the date selected are in the database, it will display the room_type_availability database.
Else if the date selected are not in database, it will display the room_type database.
Hope you guys can give some advice on it.
Thanks for helping and appreciate it.
:)