Nerds who love the symfony-project
19 Feb
In previous Symfony versions it was quite difficult and painful to link your applications together (eg frontend and backend).
Yesterday the Symfony crew posted a tutorial on how easy it is in Symfony 1.2. In essence, its a simple config change and a change to your sfApplicationConfiguration class.
However, this method does still require an absolute hard-code of your application URL within your class (or you could put it in a config setting in your app.yml and read it off there). Even though it required some hard-coding, it still is much simpler and easier to use than Symfony 1.0 and 1.1 methods.
For more information - check out the Symfony blog post.
Symfony nerds tip: To avoid hard-coding as much as possible, you could in your app.yml define your application URL’s for each environment (eg. DEV, TEST and PROD). Once you have, in your application configuration class (which extends sfApplicationConfiguration), you could read the config variable for your application URL, but automate that via sfConfig::get(’sf_environment’). And depending on what environment you are in, you will select the application URL that corresponds to that environment.
17 Feb
Today Symfony 1.1.7 has been released with 16 bugfixes. It’s important to note that no new features are introduced with these minor releases on a sable branch, meaning your upgrade path should be seamless without any hassles.
16 Feb

Far too often I’ve found my self thinking… “umm.. what’s that setting called again?”, “what are the possible values for that setting?”. Then I end up googling for quite some time to see what options I have for my Symfony settings.yml file. With over 20 different setting options, it can be quite confusing at times!
Well, Google no more!
Fabian has just posted a great overview of settings.yml as of Symfony 1.2. This great addition to the Symfony documentation is also available to download in PDF. This PDF is part of a new book that the Symfony team have planned - the ‘Symfony reference book’.
More Symfony documentation coming your way!
7 Feb
For a while now Symfony developers have been looking for a good IDE to use when developing in the Symfony framework. Some use Eclipse with PDT (PHP Development Toolkit), some use NetBeans 6.5 with it’s recent support of the PHP stack, some have tried creating Symfony-specific Eclipse plugins, without much sucess and many often prefer to use their favorite text editor.
Whatever you choose, it’s great news to see that Sun is going to back Symfony specific things in its upcoming release of NetBeans 7.0 - the framework is maturing and so are its tools.
For a while now, NetBeans have been evaulating the support of a PHP framework within it’s stack. A call out went to Symfony developers, to vote if you want it!. NetBeans then began evalutating the big response it got from Symfony developers.
Not sure if it missed most peoples radar (it missed ours!) - but late last year, Sun announced Symfony will be supported as part of NetBeans 7.0:
“The news is that the Symfony support will be part of NetBeans 7.0. We are going to start work on it very soon. I hope that it will be a part of continual build this year and community can comment the support and work with us to finish it in the best possible quality and usability”
From what we can tell from here and the product Roadmap, NetBeans 7.0 release could be ready somewhere between April and June this year.
Do you use an IDE when developing in Symfony? What do you use? Do you think you will use NetBeans 7.0? Let us know… interested to hear your thoughts…
4 Feb
Why tcpdf
TCPDF is current, well supported, well used and more up to date than equivalents such as domPDF which have had an unresolved security advisory out since 02/05/2008.
It is also very easy to integrate into a symfony project since it does not require external libraries for basic functions.
Features
The features below are from the TCPDF home page:
* no external libraries are required for the basic functions;
* supports all ISO page formats;
* supports custom page formats, margins and units of measure;
* supports UTF-8 Unicode and Right-To-Left languages;
* supports TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
* supports document encryption;
* includes methods to publish some (x)HTML code;
* includes graphic (geometric) and transformation methods;
* includes Javascript and forms support;
* includes a method to print various barcode formats (CODE 39, CODE 39 EXTENDED, Interleaved 2 of 5, CODE 128 A/B/C, EAN 13, UPC-A, POSTNET, CODABAR);
* includes methods to set Bookmarks and print a Table of Content;
* includes a method to move pages;
* includes methods for automatic page header and footer management;
* supports automatic page break;
* supports automatic page numbering and page groups;
* supports automatic line break and text justification;
* supports JPEG and PNG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick;
* supports stroke and clipping mode for text;
* supports clipping masks;
* supports Grayscale, RGB, CMYK, Spot Colors and Transparencies;
* supports several annotations, including links, text and file attachments;
* supports page compression (requires zlib extension);
* supports user rights management so Adobe Reader users can save filled-in copies of forms they complete.
Using tcpdf in a symfony project
I’m assuming here that you’re using PHP5 and that you’re happy to simply try this out by including the TCPDF libs in a project (as opposed to making them accessible by any project on your system).
Start by downloading TCPDF and unpacking this into your project lib folder … so where PROJECT is your project directory:
cd PROJECT/lib curl -O http://transact.dl.sourceforge.net/sourceforge/tcpdf/tcpdf_4_5_010.zip unzip tcpdf_4_5_010.zip
That’s it you’re ready - before commiting to svn (or your preferred code version repo) I also “clean up” the above PROJECT/lib/tcpdf/ directory by doing this:
rm -rf doc examples CHANGELOG.TXT README.TXTConfiguration
One can modify the properties of the generated PDF documents in the PROJECT/lib/tcpdf/config/tcpdf_config.php file.
These 6 settings are particularly important for the look and feel of the document.
The “my_logo.JPG” file should be placed in the PROJECT/lib/tcpdf/images/ directory.
What follows below is a list of the kind of properties you may wish to modify.
define ('PDF_PAGE_FORMAT', 'A4'); define ('PDF_PAGE_ORIENTATION', 'P'); define ('PDF_UNIT', 'mm'); define ('PDF_MARGIN_HEADER', 5); define ('PDF_MARGIN_FOOTER', 10); define ('PDF_MARGIN_TOP', 27); define ('PDF_MARGIN_BOTTOM', 25); define ('PDF_MARGIN_LEFT', 15); define ('PDF_MARGIN_RIGHT', 15); define ('PDF_FONT_NAME_MAIN', 'helvetica'); define ('PDF_FONT_SIZE_MAIN', 10); define ('PDF_FONT_NAME_DATA', 'helvetica'); define ('PDF_FONT_SIZE_DATA', 8);
Write your own class
Within the lib folder of the PROJECT, write a myPDF.php class that calls the tcpdf lib and writes a pdf file based on your PROJECT requirements.
Coupled with the configuration shown above, and the code below, it is possible to create a PDF document containing a table of data based on an array.
<?php require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/tcpdf.php'); // extend TCPF with custom functions class myPDF extends TCPDF { // Colored table public function ColoredTable($header,$data) { // setting up colours, widths and normal - not bold fontSetDrawColor(0, 0, 0); $this->SetLineWidth(0.3); $this->SetFillColor(211, 211, 211); $this->SetTextColor(0); $this->SetFont(''); // Data foreach($data as $row) { // custom call to do a two column table on one page // left column is smaller so as to accomodate longer text in the right column $this->Cell(70, 6, $row[0], 'LTR', 0, 'C', 1); $this->Cell(110, 6, $row[1], 'LTR', 0, 'C', 0); $this->Ln(); } $this->Cell(0, 0, '', 'T'); } }
The code above expects an array of data to be rendered into table rows. The array is of this format:
[0] => Array ( [0] => sfNerd: [1] => eHabib ) [1] => Array ( [0] => sfNerd: [1] => BigM ) [2] => Array ( [0] => sfNerd [1] => AK )
The following tcpdf methods are used to render the table with appropriate colours, line widths, populate content in table cells.
You can invoke the above class in the following manner (refactor to suit your needs etc). Place this code you your desired Symfony module/action.
public static function buildPDF($order_page, $myfileloc){ // array used to define the language and charset of the pdf file to be generated $language_meta = Array(); $language_meta['a_meta_charset'] = 'UTF-8'; $language_meta['a_meta_dir'] = 'ltr'; $language_meta['a_meta_language'] = 'en'; $language_meta['w_page'] = 'page'; // create new PDF document $pdf = new myPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetAuthor('An Order Form'); $pdf->SetTitle('An Order'); $pdf->SetSubject('An Order'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($language_meta); // set font $pdf->SetFont('helvetica', '', 12); // add a page $pdf->AddPage(); //Column titles $header = array('Name', 'Type'); // lets build the array of data that needs to be published in a pdf $value=''; $data = array(); // iterate the orderpage variable and build our array foreach($order_page as $key => $val) { if($val != null) { array_push($data,array($key,$val)); } } // insert a colored table into the document with the above vars // ColoredTable is the function defined in a custom class in lib/ $pdf->ColoredTable($header, $data); //Close and output PDF document $pdf->Output($myfileloc, 'F'); }
All of these methods are documented here
Documentation and further examples
Excellent documentation on all aspects of TCPDF can be found here.
Usage examples can be found here.
Using the documentation and examples, one can quickly establish how to generate PDF documents using TCPDF.
1 Feb
Today the Symfony team announced that all symfony documentation is now available as PDF files. This includes the Jobeet Tutorial for Propel, Doctrine, the Forms Book, or the Cookbook.
Apparently the PDF’s are generated nightly - so you get the most up to date every night. Awesome stuff!
Grab it all at the Symfony doco page.
If you are after some of the documentation in HTML, SymfonyNerds released the doco for Jobeet (Propel) as well as the Symfony Book (1.0, 1.1 and 1.2) and you can get that on this site.