Posted by Geert Van Damme on September 25, 2011
When storing entity objects in the http session, you might run into following exception :
ErrorException: Notice: serialize() [function.serialize]: “id” returned as member variable from __sleep() but does not exist in…
Now, apparently php has some problems serializing an object which subclasses an object with private properties. As Doctrine always creates subclasses of your entity classes (which are called Proxy classes), this means you should never use private properties (e.g. $id or any other property) on your entity (or associated entities) ! Use protected instead.
Posted by Geert Van Damme on September 1, 2011
Symfony2 contains a lot of validators out of the box, but it is not very clearly documented how to use custom messages when validation fails for these standard validators. After some investigation, I found the validation messages in
Symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Resources/translations/. It is very easy to override a message. Just look up the message you wish to modify (e.g. ‘This value should not be blank’), create your own validators.[language].yml file (or .xliff if you prefer) in your bundle, and add this message as a key with your custom message as value :
This value should not be blank: This is a required field
Posted by Geert Van Damme on August 29, 2011
I have used dompdf for the first time to generate PDF files from html content, and it seems to be working pretty well. One thing I noticed, when using UTF-8 encoding, you should add following in the head section of your html content :
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
This way, the characters will be displayed correctly in the rendered pdf.
Posted by Geert Van Damme on August 12, 2011
I was just trying to figure out why a Xapian query did not work as expected, when it hit me : i was using the word ‘and’ to combine search terms, while I should be using the capitalized word ‘AND’ instead… Stupid mistake that cost me an hour to figure out. Hence this reminder
Posted by Geert Van Damme on August 7, 2011
I recently needed to use the Zend GData component in my Symfony2 project. It is very easy to setup, but there is one mistake that I suspect some other people might make as well.
First, add the Zend library to your vendor folder (e.g.
vendor/Zend/library/Zend). As Zend does not use namespaces, you need to register the ‘Zend’ prefix instead. This can be done in the
autoload.php file located in your app folder. Apparently Zend has some problems this way with ‘require_once’ statements, hence the modification of the include path (last line) :
// ... existing code
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
'Swift_' => __DIR__.'/../vendor/swiftmailer/lib/classes',
'Zend_' => __DIR__.'/../vendor/Zend/library',
Now you are ready to use the Zend components. One mistake I made, I used the classes without a leading backslash, which does not work because the classes are in de default namespace. So, instead of using e.g.
$gdataCal = new Zend_Gdata_Calendar($client); // class not found error will be thrown
you need to add a backslash as such :
$gdataCal = new \Zend_Gdata_Calendar($client); // class is located in default namespace
Posted by Geert Van Damme on June 10, 2011
The Symfony2 book says that validation using annotations should be done as follows :
use Symfony\Component\Validator\Constraints as Assert;
I tried this on my installation, but this doesn’t work. I had to change ‘@Assert\’ into ‘@assert:’ to make it work :
Read more »
Posted by Geert Van Damme on May 26, 2011
After trying the Symfony2 framework for some days, setting up a little project with security, ORM and routing, I have found some things in the manual that were not entirely clear (or sometimes just wrong, I think). Of course it is still in beta, so I’m not blaming anyone but myself… And don’t get me wrong, I will continue using Symfony2 as it is very easy and clear to use.
Translations don’t seem to work outside bundles. I tried creating a translation file in the
app/Resources/translations folder, but Symfony2 doesn’t seem to pick it up. It does work inside bundles, so this is not really a problem for me. Don’t know of it is intended behavior either.
Read more »
Posted by Geert Van Damme on May 18, 2011
I just started developing in Symfony2, and the installation told me I should install the Intl extension (intl.so) for internationalization. Although Symfony2 works without the extension, I suspect I will run into problems sooner or later, e.g. when using the translation service. So after trying some different ways to compile and install the extension, I finally found that it is fairly easy using Macports.
Read more »
Posted by Geert Van Damme on May 12, 2011
Unlike installation of Xapian on OS-X for use with MAMP, the installation on Debian could not be more simple :
sudo apt-get install php5-xapian
Then restart your Apache server
sudo /etc/init.d/apache2 restart
And you’re done
Check phpinfo, there should be a section on Xapian now.
Posted by Geert Van Damme on April 21, 2011
I just discovered some weird behaviour using Xapian in PHP, and I think it has something to do with pointers. I tried adding two XapianDateValueRangeProcessors as follows :
$qp->add_valuerangeprocessor(new XapianDateValueRangeProcessor(0, 'created:', true, false, 1970));
$qp->add_valuerangeprocessor(new XapianDateValueRangeProcessor(1, 'updated:', true, false, 1970));
But somehow this would break Xapian (I didn’t get any error, this script just stopped completely when parsing the query).
Read more »