我正在使用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>';
}
}
我想在URL中传递
$row->companyName
作为site/companyDetail?name=CompanyName
的一部分,其中companyDetail
是文件。这些值来自SQL数据库。我要加载companyDetail
的CompanyName
。我该怎么做?谢谢。 最佳答案
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)您的视图(“ applications / views / company_detail.php”)
<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>
关于php - 方法发布并获取CodeIgniter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28253485/