首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将函数fgetcsv()中的值传递到codeigniter中的视图中?

如何将函数fgetcsv()中的值传递到codeigniter中的视图中?
EN

Stack Overflow用户
提问于 2017-06-21 06:58:28
回答 1查看 173关注 0票数 0

使用mPDF库创建PDF。文件是创建的,我尝试创建不同的PDF文件,但是它创建了我需要的文件数量,但是所有的文件都包含第一个文件的相同数据。这是我问题的一个示例代码

控制器

代码语言:javascript
复制
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller{

    public function page1(){
            $this->load->view('view_upload');

    }

        public function page2(){
       $file = fopen($_FILES['file']['tmp_name'], 'r+');          
         $i=0;

           $user['data']=fgetcsv($file);
           echo "<br><br>";
           //print_r($user);

           //load the view and saved it into $html variable
             $html=$this->load->view('print_1', $user, true);

           //this the the PDF filename that user will get to download
            $pdfFilePath = $i.".pdf";

           //load mPDF library
            $this->load->library('m_pdf');

           //generate the PDF from the given html
            $this->m_pdf->pdf->WriteHTML($html);

           //download it.
            $this->m_pdf->pdf->Output("output/".$pdfFilePath, 'F');



           ++$i;
           $html=$this->load->view('print', $user, true);

           //this the the PDF filename that user will get to download
            $pdfFilePath = $i.".pdf";

           //load mPDF library
            $this->load->library('m_pdf');

           //generate the PDF from the given html
            $this->m_pdf->pdf->WriteHTML($html);

           //download it.
            $this->m_pdf->pdf->Output("output/".$pdfFilePath, 'F');

        fclose($file); 

}
}

视图是:

print_1

代码语言:javascript
复制
<?php
echo "print_1";
?>

打印

代码语言:javascript
复制
<?php
echo "print";
?>

它创建了两个PDF文件,它们都有数据"print_1“。备注:变量$user没有使用,而是在我的实际代码中使用。

EN

回答 1

Stack Overflow用户

发布于 2017-06-21 11:10:52

试试这个(真的那么明显吗?)

在你的print.php里

代码语言:javascript
复制
foreach($data AS $key => $arrData)
{
    echo implode(",",$arrData);
    echo "<br />";
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44668870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档