使用codeigniter从mysql数据库导出pdf文件
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有提供任何有关什么不起作用以及您的 cezpdf 库做什么的信息,我只能说您的代码
调用了错误的方法,除非您有一些没有告诉我们的路由。要在控制器中调用 topdf() 方法,您需要使用:
我正在等待更多信息来继续猜测。
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
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:
I'm waiting for more info to go on guessing.