如何在codeigniter中将按钮重定向到外部链接?

时间:2017-01-08 11:42:05

标签: javascript php ajax codeigniter

我是新手。我非常需要你帮助解决这个问题。

我想将按钮名称'lihat rincian'与每行表格相关联,以重定向到http://website.com/等外部链接

My view of datatables Image

视图是数据表,该按钮位于我的控制器上。之前链接到其他页面的功能是'detail',而数据表的列表是'ajax_list2'。有关信息,我的数据库名称为'crud',表格为'edulib'

这是我的控制器。控制器名称:edulibs

/*for load */
public function detail()
	{
		$this->session->set_userdata('url',current_url());
		$id=$this->uri->segment(3);
		$data['detail']=$this->edulib_model->get_where('edulib','id',$id);
		$this->load->helper('url');
		$this->load->view('profil',$data);
		
	}

/* for list */
public function ajax_list2()
	{
		$list = $this->edulibs->get_datatables();
		$data = array();
		$no = $_POST['start'];
		foreach ($list as $edulibs) {
			$no++;
			$row = array();
			$row[] = $edulibs->nama;
			$row[] = $edulibs->pembimbing1;
			$row[] = $edulibs->pembimbing2;
			$row[] = $edulibs->subyek;
			$row[] = $edulibs->judul;
			$row[] = $edulibs->tanggal;

			//add html for action
			$row[] = '<a class="btn btn-sm btn-primary center-block" href="'."detail/".$edulibs->id."".'" title="Tampilkan"><i class="glyphicon glyphicon-eye-open"></i> Lihat Rincian</a>';
		
			$data[] = $row;
		}

		$output = array(
						"draw" => $_POST['draw'],
						"recordsTotal" => $this->edulibs->count_all(),
						"recordsFiltered" => $this->edulibs->count_filtered(),
						"data" => $data,
				);
		//output to json format
		echo json_encode($output);
	}

非常感谢你的帮助。我非常需要你的帮助 抱歉英文不好。

1 个答案:

答案 0 :(得分:-1)

假设您通过外部链接在新标签中表示您可以在链接中添加目标属性,对于网站链接,您只需更改href值,如下所示:

<a class="btn btn-sm btn-primary center-block" href="http://website.com/" target="_blank" title="Tampilkan"><i class="glyphicon glyphicon-eye-open"></i> Lihat Rincian</a>