你好我是codeigniter的新手,当我开发我的第一个网站时我遇到了问题
我有一个API,这里是我的网址API示例
API显示所有文章
http://localhost/vectorkey/oneportalbackend/api/articles
API详情文章
http://localhost/vectorkey/oneportalbackend/api/articles?id_news=13
该API显示的文章数据与id_news相等13
我希望使用该API显示详细文章,并在我点击网站上的按钮时动态填充参数id_news。
这是我的按钮代码:
<a href="<?= base_url().'admin/Articles/detail/'.$row->id_news ?>">
<button class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="Detail"><i class="fa fa-eye"></i></button>
</a>
我尝试了很多次,但我不知道将id_news传递给控制器, 这是我的控制器代码:
public function detail()
{
$data['master'] = json_decode($this->curl->simple_get('http://localhost/vectorkey/oneportalbackend/api/articles'));
$data['datanews'] = json_decode($this->curl->simple_get('http://localhost/vectorkey/oneportalbackend/api/articles?id_news='.$data['master']['id_news']));
$this->load->view('admin/articles_detail',$data);
}
我收到了错误
A PHP Error was encountered
Severity: Notice
Message: Undefined index: id_news
Filename: admin/Articles.php
Line Number: 106
Backtrace:
File: D:\RIFQI_FILE\xampp\htdocs\vectorkey\oneportal\application\controllers\admin\Articles.php
Line: 106
Function: _error_handler
File: D:\RIFQI_FILE\xampp\htdocs\vectorkey\oneportal\index.php
Line: 304
Function: require_once
答案 0 :(得分:1)
这应该有效。获取索引为0的数组值,如$ arr [0] - &gt; id_news。
public function detail()
{
$arr = $data['master'] = json_decode($this->curl->simple_get('http://localhost/vectorkey/oneportalbackend/api/articles'));
$data['datanews'] = json_decode($this->curl->simple_get('http://localhost/vectorkey/oneportalbackend/api/articles?id_news='.$arr[0]->id_news));
$this->load->view('admin/articles_detail',$data);
}