将用户重定向到单击的相应 table 单元格
Redirecting user to the respective table cell clicked
目前在我看来 table class 正在使用 foreach 循环从后端填充数据。我为 table 的每一行都有一个编辑单元格,当单击 ID 为 1 的单元格并且该页面应显示所有id 为 1 的用户的数据。我使用以下代码来实现此目的:
查看 Class(index.php):
<?php
foreach($records as $row ){
?>
<tr>
<td><?= $row->refno ?></td>
<td><?= $row->display_name ?></td>
<td><a href="contacts/edit/'.$row->id.'">
<span class="sr-only">edit</span></a>
</td>
<td></td>
</tr>
控制器Class:
public function lists($type='')
{
$main['records']=$this->contacts_model->get_records();
$main['page'] = 'crm/contacts/index';
$this->load->view('crm/index',$main);
}
public function edit($slug='')
{
$main['page'] = 'crm/contacts/edit';
$this->load->view('crm/index',$main);
}
型号Class:
function get_records(){
$this->db->select("*");
$this->db->from("contacts");
$this->db->where("status='Y'");
$query = $this->db->get();
return $query->result();
}
// I want another method here that will fetch the details as per the id that was selected
所以这里我有 2 个问题,1 是我的 <a>
标签在我将其设置为 contacts/edit/'.$row->id.'
后没有将我带到相应的 id,2 是我如何显示我的 contacts/edit 视图 class.
中 ID 为 1 的人的详细信息
解决你的第一个问题很简单。你犯了一个简单的语法错误:
错误:
<?php
...
<td><a href="contacts/edit/'.$row->id.'">
...
正确:
<?php
...
<td><a href="<?= 'contacts/edit/'. $row->id ?>">
...
注意: 短格式回显 (<?= "some text or variables" ?>
) 仅在 short_open_tags 标志为 已在 php.ini!
中启用
对于第二个问题,您需要在控制器中创建另一个功能,该功能收集并显示带有基于 ID 的数据的视图。
目前在我看来 table class 正在使用 foreach 循环从后端填充数据。我为 table 的每一行都有一个编辑单元格,当单击 ID 为 1 的单元格并且该页面应显示所有id 为 1 的用户的数据。我使用以下代码来实现此目的:
查看 Class(index.php):
<?php
foreach($records as $row ){
?>
<tr>
<td><?= $row->refno ?></td>
<td><?= $row->display_name ?></td>
<td><a href="contacts/edit/'.$row->id.'">
<span class="sr-only">edit</span></a>
</td>
<td></td>
</tr>
控制器Class:
public function lists($type='')
{
$main['records']=$this->contacts_model->get_records();
$main['page'] = 'crm/contacts/index';
$this->load->view('crm/index',$main);
}
public function edit($slug='')
{
$main['page'] = 'crm/contacts/edit';
$this->load->view('crm/index',$main);
}
型号Class:
function get_records(){
$this->db->select("*");
$this->db->from("contacts");
$this->db->where("status='Y'");
$query = $this->db->get();
return $query->result();
}
// I want another method here that will fetch the details as per the id that was selected
所以这里我有 2 个问题,1 是我的 <a>
标签在我将其设置为 contacts/edit/'.$row->id.'
后没有将我带到相应的 id,2 是我如何显示我的 contacts/edit 视图 class.
解决你的第一个问题很简单。你犯了一个简单的语法错误:
错误:
<?php
...
<td><a href="contacts/edit/'.$row->id.'">
...
正确:
<?php
...
<td><a href="<?= 'contacts/edit/'. $row->id ?>">
...
注意: 短格式回显 (<?= "some text or variables" ?>
) 仅在 short_open_tags 标志为 已在 php.ini!
对于第二个问题,您需要在控制器中创建另一个功能,该功能收集并显示带有基于 ID 的数据的视图。