duan2428 2011-11-02 19:40
浏览 66

使用codeigniter从mysql数据库导出pdf文件

using codeigniter I create a form where i insert data into MySQL database. After complete insert i want to retrieve data as PDF file.

In modeld my file name- membership_model.php. In view page I have form name- send_form.php but after send data i have a successful page name signup_successful.php here is a link export as pdf button who call topdf() in login page. but is doesn't work. please help in topdf function.

in view folder- signup_successful.php

<p>Your data has been sent. 
<?php echo anchor('topdf', 'Export as PDF');?>
</p>

controllers folder

login.php

<?php

class Login extends Controller {

    function index()
    {
       parent::Controller();
           $this->load->helper('pdf_helper');
    }


    function data_info()
    {
        $data['main_content'] = 'data_form';
        $this->load->view('includes/template', $data);
    }

    function sent_data()
    {
        $this->load->library('form_validation');
        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');

        if($this->form_validation->run() == FALSE)
        {
        $this->load->view('data_form');
        }
        else
        {           
        $this->load->model('membership_model');
        if($query = $this->membership_model->send_data())
               //create_member call model create_member
        {
           $data['main_content'] = 'signup_successful';
           $this->load->view('includes/template', $data);
        }
        else
        {
            $this->load->view('data_form');
            }
         }  
    }

    function topdf () 
    {
       $this->load->library('cezpdf');
       $this->load->helper('pdf_helper');
       prep_pdf();
       $data['member']= $this->membership_model->alldata();
       $titlecolumn = array(
                'first-name' => 'First-name',
                'last_name' => 'Last_name',
                'email_address' => 'Email_address'
                       );
       $this->cezpdf->ezTable($data['member'], $titlecolumn,'Member Data');
       $this->cezpdf->ezStream();
    }
}
  • 写回答

1条回答 默认 最新

  • dongliehuan3925 2011-11-02 20:35
    关注

    Since you didn't provide any info on what is not working and what does your cezpdf library do I can only say that your code

    <?php echo anchor('topdf', 'Export as PDF');?>
    

    is calling the wrong method, unless you have some routing you didn't tell us. To call the topdf() method in your controller you need to use:

    <?php echo anchor('login/topdf', 'Export as PDF');?>
    

    I'm waiting for more info to go on guessing.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大