方法Post和Get In CodeIgniter

时间:2015-01-31 15:50:34

标签: php html mysql forms codeigniter

我正在使用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}}。我该怎么做?谢谢。

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>