嗨,我有一个简单的图像形式,用户可以单击它,根据单击的图像,模态对话框将显示数据库中的数据列表。我有这个工作,我在 mysql 语句中声明特定的列名,而不是通过变量。我希望能够知道如何/在何处将图像输入的值从视图传递到控制器,以便它可以在视图中的 mysql 语句中使用。我已经将 mysql 语句从控制器传递到模型到视图。下面是我的代码。任何帮助将不胜感激,因为我是 CI 的新手并且有点困惑。谢谢!
控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class App extends MY_Controller {
function __construct()
{
parent::__construct();
log_message('debug', 'App controller has been initialized');
}
public function toolsmodal()
{
$Dept = $this->input->post('submit');
//echo $Dept;
$this->load->model('tools_model');
$tools = $this->tools_model->getTools($Dept);
$data['tools'] = $tools;
$data['view'] = 'datatables';
$this->load->view('templates/default', $data);
}
public function index()
{
$data['view'] = 'datatables';
$this->load->view('templates/default', $data);
}
public function welcome()
{
$data['view'] = 'welcome';
$this->load->view('templates/default', $data);
}
public function datatables()
{
// You can safely delete this method. It is an example.
$data['view'] = 'datatables';
$this->load->view('templates/default', $data);
}
}
模型:
class Tools_model extends CI_Model
{
public function getTools($Dept)
{
//$query = $this->db->query("select rname,decription,DRI,developer, golive from web.reportdash where AppleStore = 'Yes'");
$this->db->select('rname, decription, DRI, developer, golive');
$this->db->where($Dept, 'Yes');
$query = $this->db->get('web.reportdash');
$tools = array();
foreach ($query->result() as $row) {
$tools[] = $row;
}
return $tools;
}
} ?>
看法:
<table>
<tr>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-applestore' src="<? echo base_url("/_assets/img/store.png"); ?>" name='submit' value='Store'> <br>AppleStore</td>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"> <input type='image' id='filters-trigger-storef' src="<? echo base_url("/_assets/img/finance.png"); ?>" name='submit' value='Finance'><br>Finance</td>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storel' src="<? echo base_url("/_assets/img/logistics.png"); ?>" name='submit' value='Logistics'> <br>Logistics</td>
</tr>
<tr></tr>
<tr>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storeman' src="<? echo base_url("/_assets/img/manufacturing.jpg"); ?>" name='submit' value='Manufacturing'><br>Manufacturing</td>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storect' src="<? echo base_url("/_assets/img/control.jpg"); ?>" name='submit' value='ControlTower'><br>Control Tower</td>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"><input type='image' id='filters-trigger-storeom' src="<? echo base_url("/_assets/img/OM.jpg"); ?>" name='submit' value='OrderManagement'><br>Order Management</td>
</tr>
<td style="text-align:center;font-weight:bold;width:300px;font-size:14px;color: #ffffff;"> <input type='image' id='filters-trigger-stores' src="<? echo base_url("/_assets/img/sales.jpg"); ?>" name='submit' value='Sales'><br>Sales</td>
</tr>
</table>
</form>
</div>
<div class="container">
<div class="filters-trigger-applestorem not-displayed modal1 hide fade in" style="overflow:auto;">
<button type="button" id='close' class="close" data-dismiss="filters-trigger-applestorem">×</button>
<table class="table table-bordered smaller-font margin-top-medium" style="margin: 0;">
<thead>
<tr>
<td>Report Name</td>
<td>Description</td>
<td>DRI</td>
<td>Developer</td>
</tr>
</thead>
<tbody>
<?php foreach($tools as $tool):
?>
<tr class="padding-larger-right table-header"><td><?= $tool->rname; ?> </td>
<td class="smaller-padding vertical-centred"><?= $tool->decription; ?></td>
<td class="smaller-padding vertical-centred"><?= $tool->DRI; ?></td>
<td class="smaller-padding vertical-centred"><?= $tool->developer; ?></td>
<?php
endforeach ?>
</tbody>
</table>
</div>