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

发布于 2024-12-13 11:45:07 字数 2363 浏览 0 评论 0原文

使用 codeigniter 创建一个表单,将数据插入 MySQL 数据库。完成插入后,我想以 PDF 文件形式检索数据。

在模型中我的文件名 -membership_model.php。 在视图页面中,我有表单名称- send_form.php 但发送数据后,我有一个成功的页面名称signup_successful.php,这里有一个链接导出为pdf按钮,在登录页面中调用topdf() 。但这不起作用。请帮助 topdf 功能。

在视图文件夹-signup_successful.php

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

控制器文件夹

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();
    }
}

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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2024-12-20 11:45:07

由于您没有提供任何有关什么不起作用以及您的 cezpdf 库做什么的信息,我只能说您的代码

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

调用了错误的方法,除非您有一些没有告诉我们的路由。要在控制器中调用 topdf() 方法,您需要使用:

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

我正在等待更多信息来继续猜测。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文