我正在使用CodeIgniter。
if(isset($query1))
{
foreach($query1 as $row)
{
echo '<tr>';
echo '<td><a href="'.base_url().'site/companyDetail">'.$row->companyName.'</a></td>';
echo '<td>'.$row->address.'</td>';
echo '<td>'.$row->contactPerson.'</td>';
echo '<td>'.$row->contactnum.'</td>';
echo '</tr>';
}
}
我想将网址中的$row->companyName
传递给site/companyDetail?name=CompanyName
,其中companyDetail
是一个文件。值来自SQL数据库。我想加载companyDetail
的{{1}}。我该怎么做?谢谢。
答案 0 :(得分:0)
1)将 $row->companyName
作为参数
if(isset($query1))
{
foreach($query1 as $row)
{
echo '<tr>';
echo '<td><a href="'.base_url().'site/companyDetail/"'.$row->companyName.'>'.$row->companyName.'</a></td>';
echo '<td>'.$row->address.'</td>';
echo '<td>'.$row->contactPerson.'</td>';
echo '<td>'.$row->contactnum.'</td>';
echo '</tr>';
}
}
2)点击链接后,它会到达你的控制器(applications / controllers / site.php),
class Site extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function companyDetail($companyName)
{
// Uncomment below to check whether you are getting company name
// echo $companyName; exit;
$data['company'] = $this->abc_model->get_company_details($companyName);
// Uncomment below to check the data
// echo '<pre>'; print_r($data); exit;
$this->load->view('views/company_detail.php', $data);
}
}
3)您的观点(&#34; applications / views / company_detail.php&#34;)
<table>
<?php foreach($company as $c) { ?>
<tr>
<td><?php echo $c['name']; ?></td>
<td><?php echo $c['founder']; ?></td>
<td><?php echo $c['assets']; ?></td>
</tr>
<?php } ?>
</table>