我希望能够在我之前制作的控制器上访问此变量
这是我视图中的代码
<tbody>
<?php foreach ($data->result() as $row):?>
<tr>
<td><?php echo $row->nama; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->password; ?></td>
<td>
<a href="<?php echo site_url('login/edit/'.$row->username); ?>">Edit</a> |
<a href="<?php echo site_url('login/delete/'.$row->username); ?>" onCLick="return confirm('Are you sure you want to delete this item?')">DELETE</a> |
</td>
</tr>
<?php endforeach; ?>
</tbody>
我在控制器名称Login上放了一些包含该变量的方法,但我将默认控制器设置为News。我想从登录控制器访问该变量。
这是我的登录控制器
public function index()
{
$this->$data['login'] = $this->Login_Model->get_news();
$this->$data['title']= 'Data Pendaftaran';
// konfigurasi pagination//
$config['base_url'] = site_url('Login/index');
$config['total_rows'] = $this->db->count_all('anggota');
$config['per_page'] =4;
$config["uri_segment"] =3;
$choice = $config["total_rows"]/ $config["per_page"];
$config["num_links"] =floor($choice);
// style pagination untuk bootstrap v4//
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class = "pagination justify-content-center">';
$config['full_tag_close'] = '</ul></nav></div>';
$config['num_tag_open'] ='<li class="page-item"><span class ="page-link">';
$config['num_tag_close'] ='</span></li>';
$config['cur_tag_open'] ='<li class="page-item active"><span class="page-link">';
$config['cur_tag_close'] ='<span class="sr-only">(current)</span></span></li>';
$config['next_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['next_tagl_close'] ='<span aria-hidden="true">»</span></span></li>';
$config['prev_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['prev_tagl_close'] ='</span>Next</li>';
$config['first_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['first_tagl_close'] = '</span></li>';
$config['last_tag_open'] ='<li class="page-item"><span class="page-link">';
$config['last_tagl_close'] ='</span></li>';
$this->pagination->initialize($config);
$data['page']=($this->uri->segment(3))? $this->uri->segment(3) : 0;
$data['data'] = $this->Login_Model->get_data_list($config["per_page"],$data['page']);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('anggotapendaftaran',$data);
}
对不起我的坏话
答案 0 :(得分:0)
您可以通过以下方式完成此操作:
在Controller上,在您加载视图的所有代码之后:
$data = array();
$data['title'] = 'Data Pendaftaran';
$this->load->view("yourviewname_view", $data);
在View上,当你想获得标题时,你可以像$ data一样得到它 例如:
echo $data; //will give you "Data Pendaftaran"
如果是数组,您可以像以下一样访问它:
echo $data['arrayKey'];
或
echo $data['pagination'];
我希望这会有所帮助