我对codeigniter相当陌生。
我的 views/check_availability/index.php 文件中有以下代码:
<?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 ?>
这是我在 models/check_availabiliy_model.php 文件下的代码
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();
}
这是我的控制器/check_availability.php 文件中的代码
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');
}
在views/check_availability/index.php 文件下,当我根据POST 方法(如$type = $_POST['type'])调用check_availability 函数时,我想过滤room_type 字段。
目前,这是我用来从 lf_rooms 表中查询所有记录的代码:
<?php foreach ($check_availability as $check_availability_item): ?>
但是如何将 $type 变量的值传递给 check_availability 函数?