Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]object not found
#1

[eluser]diasansley[/eluser]
i am using the following controller but when i say localhost/codeigniter/pdf_test
it says object cannot be found.


Code:
<?php
class pdf_test extends Controller {

    function pdf_test()
    {
        parent::Controller();
    }

    function tcpdf()
    {
        $this->load->library('pdf');

        // set document information
        $this->pdf->SetSubject('TCPDF Tutorial');
        $this->pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        
        // set font
        $this->pdf->SetFont('times', 'BI', 16);
        
        // add a page
        $this->pdf->AddPage();
        
        // print a line using Cell()
        $this->pdf->Cell(0, 12, 'Example 001 - €à èéìòù', 1, 1, 'C');
        
        //Close and output PDF document
        $this->pdf->Output('example_001.pdf', 'I');        
    }
}
?>

Thanks Rgds
#2

[eluser]InsiteFX[/eluser]
localhost/codeigniter/pdf_test/tcpdf

Or change the function name from tcpdf to index.

InsiteFX
#3

[eluser]diasansley[/eluser]
is the program correct coz it still returns object not found!@
#4

[eluser]smilie[/eluser]
Have you removed index.php yourself from the url? Default installation URL would be:

localhost/codeigniter/index.php/pdf_test/tcpdf

Also, post exact error please.

Cheers,
Smilie
#5

[eluser]diasansley[/eluser]
thanks ur the best!!!! it workd now!!

using the same function above how can i read from the database and write it to the pdf?


Thanks
#6

[eluser]smilie[/eluser]
Hi,

Here is the basis, you make it work :-)

Code:
class pdf_test extends Controller {

    function pdf_test()
    {
        parent::Controller();
    }

    function tcpdf()
    {
        $this->load->library('pdf');

        // set document information
        $this->pdf->SetSubject('TCPDF Tutorial');
        $this->pdf->SetKeywords('TCPDF, PDF, example, test, guide');
        
        // set font
        $this->pdf->SetFont('times', 'BI', 16);
        
        // add a page
        $this->pdf->AddPage();
        
        # Load model which will get data from database
        $this->load->model('your_model');
        $pdf_data = $this->your_model->getData();
        // print a line using Cell()
        # $this->pdf->Cell(0, 12, 'Example 001 - €à èéìòù', 1, 1, 'C');
        $this->pdf->Cell(0, 12, $pdf_data, 1, 1, 'C');
        
        //Close and output PDF document
        $this->pdf->Output('example_001.pdf', 'I');        
    }
}

your_model.php (which should be in directory models :-))

Code:
Class Your_model extends Model
{
    function getData()
    {
       $this->db->select('some_field')->from('some_table')->where('some_search_field','search this');
       $q = $this->db->get();
       $result = $q->result_array();
       return $result;
    }
}
#7

[eluser]diasansley[/eluser]
made changes and again :


Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\CodeIgniter\system\application\models\your_model.php:23)

Filename: tcpdf/tcpdf.php

Line Number: 7996

TCPDF ERROR: Some data has already been output to browser, can't send PDF file
thanks
#8

[eluser]smilie[/eluser]
Hi,

Can you post line 23 of your_model.php.

Cheers,
Smilie
#9

[eluser]diasansley[/eluser]
Here is my model code

Code:
<?php

Class Your_model extends Model
{  

    function __construct()
    {
      parent::__construct();
     $this->table = 'news';
      
      }


    function getData()
    {
       $this->db->select('title')->from('news');
       $q = $this->db->get();
       $result = $q->result_array();
       return $result;
    }
}

?>
#10

[eluser]smilie[/eluser]
Line 23 is end of your model file.
Can you check you do not have spaces or empty lines in that file?

Cheers,
Smilie




Theme © iAndrew 2016 - Forum software by © MyBB