2011-11-02 128 views
0

使用codeigniter我創建一個表單,我將數據插入MySQL數據庫。完成插入後,我想檢索數據爲PDF文件。使用codeigniter導出來自mysql數據庫的pdf文件

在modeld我的文件名 - 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(); 
    } 
} 
+2

*「但是不起作用」*不會飛到這裏。更加詳細一些。 –

+0

那麼有沒有錯誤,它是壞的? – MonkeyZeus

回答

0

既然你沒有提供任何信息,什麼是不工作的,什麼是你的cezpdf庫嗎我只能說你的代碼

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

是調用錯誤的方法,除非你有一些路由你沒有告訴我們。要在您的控制器中調用topdf()方法,您需要使用:

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

我在等待更多信息繼續猜測。

+0

我把數據從數據庫這個function--功能ALLDATA() \t \t \t \t { \t \t \t \t \t $ Q = $這個 - > DB->獲取( '會員'); \t \t \t \t \t \t \t如果($ Q-> NUM_ROWS()> 0){ \t \t \t \t \t \t的foreach($ Q->結果()作爲$行){ \t \t \t \t \t \t \t $ data [] = $ row; \t \t \t \t \t \t} \t \t \t \t \t \t回$的數據; \t \t \t \t \t} \t \t \t \t \t \t \t \t \t}但主要問題是topdf()。 –

+0

成員資格是我的表名 –

+0

@Arifkarim您糾正了anchor()函數嗎?你有沒有嘗試刪除對cezpdf庫的調用,看看問題是否存在? –

相關問題