php - Passing ID from json to controller with codeigniter CURL

634

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
829

Answer

Solution:

This should work. Get array values with index 0, like $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);
    }

People are also looking for solutions to the problem: How to update rows with same ID but different values in PHP MySQL

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.