I am fairly new to codeigniter.
I have the following code in my views/check_availability/index.php file:
<?php $type = $_POST['type']; ?>
<a href="/reservation/check_availability/create">Create Reservation</a>
<?php foreach ($check_availability as $check_availability_item): ?>
<h2><?php echo $check_availability_item['room_type'] ?></h2>
<div id="main">
<?php echo $check_availability_item['room_description'] ?>
</div>
<p><a href="check_availability/<?php echo $check_availability_item['id'] ?>">View article</a></p>
<?php endforeach ?>
This is my code under models/check_availabiliy_model.php file
public function check_availability($type = FALSE)
{
if ($type === FALSE)
{
$query = $this->db->get('lf_rooms');
return $query->result_array();
}
$query = $this->db->get_where('lf_rooms', array('type' => $type));
return $query->row_array();
}
This is the code in my controllers/check_availability.php file
public function index()
{
$data['check_availability'] = $this->check_availability_model->check_availability();
$data['title'] = 'Available Roooms';
$this->load->view('templates/header', $data);
$this->load->view('check_availability/index', $data);
$this->load->view('templates/footer');
}
Under views/check_availability/index.php file I want to filter the room_type field when I call the check_availability function based on the value from POST method like $type = $_POST[‘type’].
Currently this is the code that I used to query all the record from lf_rooms table:
<?php foreach ($check_availability as $check_availability_item): ?>
but how can I pass the value of $type variable to check_availability function?
You should get the
POSTparameter in the controller, query the database accordingly and only display the results in the view. The view should not hold any logic.