[英]Passing ID from json to controller with codeigniter CURL
您好,我是Codeigniter的新手,開發我的第一個網站時遇到問題
我有一個API,這里是我的url 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的數組值,例如$ arr [0]-> 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.