如何根据ID显示表格数据?

时间:2019-07-10 12:27:57

标签: php

我使用vuforia API来获取ID和数据。我不明白如何使表中的数据与ID相匹配。因为我有两个类可以执行此操作,所以第一个有一个GetAlltargets类来获取ID,第二个有一个GetTarget类来获取数据。但是当我想显示数据时,我必须在班级上手动输入ID。如何从GetAlltargets类中获取ID并将其提供给GetTarget类

我的模型GetAllTargets(显示ID)

public function execGetAllTargets(){

        $this->request = new HTTP_Request2();
        $this->request->setMethod( HTTP_Request2::METHOD_GET );

        $this->request->setConfig(array(
                'ssl_verify_peer' => false
        ));

        $this->request->setURL( $this->url . $this->requestPath );

        // Define the Date and Authentication headers
        $this->setHeaders();

        try {

            $response = $this->request->send();

            if (200 == $response->getStatus()) {
                //echo $response->getBody();
                $hasil = json_decode($response->getBody());
                $json = $hasil->results;
                return $json;
            } else {
                echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
                        $response->getReasonPhrase(). ' ' . $response->getBody();
            }
        } catch (HTTP_Request2_Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }
    }

我的模型GetTarget(显示数据)

private $targetId   = "f248175c2a6f4bcf9d9df6fe3e367ab5"; //Manually target id
    private $url        = "https://vws.vuforia.com";
    private $requestPath = "/targets/";// . $targetId;
    private $request;

    function GetTarget(){
        $this->requestPath = $this->requestPath . $this->targetId;


    }

    public function execGetTarget(){

        $this->request = new HTTP_Request2();
        $this->request->setMethod( HTTP_Request2::METHOD_GET );

        $this->request->setConfig(array(
                'ssl_verify_peer' => false
        ));

        $this->request->setURL( $this->url . $this->requestPath);

        // Define the Date and Authentication headers
        $this->setHeaders();


        try {

            $response = $this->request->send();

            if (200 == $response->getStatus()) {
                $hasil = json_decode($response->getBody());
                $json = $hasil->target_record;
                return $json;
            } else {
                echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
                        $response->getReasonPhrase(). ' ' . $response->getBody();
            }
        } catch (HTTP_Request2_Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }


    }

我的控制器

public function index()
    {   
        $data['id'] = $this->model('GetAllTargets')->execGetAllTargets();
        $data['isi'] = $this->model('GetTarget')->execGetTarget();
        $this->view('templates/header');
        $this->view('home/index', $data);
        $this->view('templates/footer');
    }

我的观点

<?php  foreach( $data['id'] as $row) { ?> 
                    <tr>
                      <td>
                        <?php echo $row;  ?>
                      </td>
                      <td>
                       <?php print_r($data['isi']->name); ?>
                      </td>
                      <td>
                         <?php print_r($data['isi']->tracking_rating); ?>
                      </td>
                      <td>
                         <a class="btn btn-primary" href="#" role="button">Update</a>
                      </td>
                    </tr>
                  <?php } ?>

0 个答案:

没有答案