php - Passing ID from json to controller with codeigniter CURL
Hello i new on codeigniter, and i have problem when i develop my first website
I have an API, here my url API example
API SHOW ALL ARTICLES
http://localhost/vectorkey/oneportalbackend/api/articles
API DETAIL ARTICLES
http://localhost/vectorkey/oneportalbackend/api/articles?id_news=13
that API is show articles data with id_news is equal 13
I want show the detail articles with that API , and fill the parameter id_news dynamically when i click button in my website.
here my button code:
<a href="<?= base_url().'admin/Articles/detail/'.$row->id_news ?>">
<button type="button" data-toggle="tooltip" title="Detail"><i ></i></button>
</a>
i tried many times,but i don't know to passing id_news to the controller, here my controller code :
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);
}
i got an error
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
Answer
Solution:
This should work. Get array values with index 0, like $arr[0]->id_news.