[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
[eluser]InsiteFX[/eluser]
localhost/codeigniter/pdf_test/tcpdf
Or change the function name from tcpdf to index.
InsiteFX
[eluser]diasansley[/eluser]
is the program correct coz it still returns object not found!@
[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
[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
[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;
}
}
[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
[eluser]smilie[/eluser]
Hi,
Can you post line 23 of your_model.php.
Cheers,
Smilie
[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;
}
}
?>
[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
|