警告消息:非法字符串偏移

时间:2017-09-07 08:37:35

标签: php codeigniter

我正在尝试在视图中打印数据,但我收到了非法的字符串偏移警告。 data1数组包含我想在视图中显示的数据。 我试图在视图中打印数据,但我收到非法的字符串偏移警告。 data1数组包含我想在视图中显示的数据。

我的控制器功能:

public function banker_offers_list() {

        $banker_id = $this->session->userdata('adminid');
        $jobs = $this->Admin_model->get_all_partner_jobs($banker_id); 
        foreach($jobs as $item)
        {
            $job_id = $item['job_id'];
            $uid = $item['uid']; 
            $campaign_id = $item['campaign_id']; 
            $campaign_name = $this->Admin_model->get_campaign_name_by_id($campaign_id); 
            $offer_id = $this->Admin_model->get_offer_id($campaign_id,$uid); //var_dump($offer_id);
            $buyer_receipt = $this->Admin_model->get_buyer_receipt_by_offer_id($offer_id); //var_dump($buyer_receipt);

            $data1 = array(
            "job_id" => $job_id,    
            "uid" => $uid,
            "campaign_id" => $campaign_id,
            "campaign_name" => $campaign_name,
            "offer_id" => $offer_id,
            "buyer_receipt" => $buyer_receipt,
            );

        }


        $data['data1'] = $data1; 

        $data['page_title'] = 'Banker Offers list - PinkStar';
        $this->load->view('admin/banker_offers_list',$data);
    }

我的观点:

<?php
    if(count($data1) > 0){
    foreach ($data1 as $d){  
        $job_id = $d['job_id']; 
        $campaign_id = $d["campaign_id"];
        $buyer_receipt = $d['buyer_receipt'];
    ?>
        <tr>
            <td>
            <?php
                echo '#'.$d['offer_id'];
            ?>

            <td>
            <?php
                echo $d['campaign_name'];

            ?>
            </td>

            <td>
                <a href="<?php echo base_url(); ?>admin/admin/banker_campaign_details/<?php echo $campaign_id; ?>" target="_blank">
                View Campaign Details</a>
            </td>
            <td>
            <?php
                $index = stripos($buyer_receipt,'*');
                $filename = substr($buyer_receipt, 0, $index);  ?>
                <a href="<?php echo base_url(); ?>upload/home/staffs/<?php echo $filename; ?>">Download  Receipt</a>

            </td>
            <td>
                <a href="<?php echo base_url(); ?>admin/admin/partner_download_receipt">Download PDF
                </a>
            </td>
        </tr>
    <?php
    }
}else{ ?>
    <tr><td colspan="6" class="no_records">There are no records available!</td></tr>
<?php } ?>

1 个答案:

答案 0 :(得分:2)

更改您的代码,如下所示(更改已注释): -

在控制器中: -

public function banker_offers_list() {

    $banker_id = $this->session->userdata('adminid');
    $jobs = $this->Admin_model->get_all_partner_jobs($banker_id); 
    $data['data1'] = []; //create an empty array
    foreach($jobs as $item)
    {
        $job_id = $item['job_id'];
        $uid = $item['uid']; 
        $campaign_id = $item['campaign_id']; 
        $campaign_name = $this->Admin_model->get_campaign_name_by_id($campaign_id); 
        $offer_id = $this->Admin_model->get_offer_id($campaign_id,$uid); //var_dump($offer_id);
        $buyer_receipt = $this->Admin_model->get_buyer_receipt_by_offer_id($offer_id); //var_dump($buyer_receipt);

        $data['data1'][] = array(
        "job_id" => $job_id,    
        "uid" => $uid,
        "campaign_id" => $campaign_id,
        "campaign_name" => $campaign_name,
        "offer_id" => $offer_id,
        "buyer_receipt" => $buyer_receipt,
        ); //assign value to array

    }

    $data['page_title'] = 'Banker Offers list - PinkStar';
    $this->load->view('admin/banker_offers_list',$data);
}

在视图中只更改了这么多代码: -

<?php
if(count($data['data1']) > 0){
foreach ($data['data1'] as $d){  
    $job_id = $d['job_id']; 
    $campaign_id = $d["campaign_id"];
    $buyer_receipt = $d['buyer_receipt'];
?>