Skip to main content

Posts

Symfony2 choice list type for MongoDB backed forms

A couple of days ago, I had to implement a select field representing a one-to-one MongoDB relationship in one of my Symfony2 forms. Having spent some time reading the documentation, I decided to use the entity form field type for this purpose. class AcmeFormType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('parent', 'entity', array( 'class' => 'Acme\MyBundle\Document\MyDocument', 'property' => 'name', 'label' => 'Parent', 'empty_value' => 'Root' )); } } And I got presented with this exception: Class Acme\MyBundle\Document\MyDocument is not a valid entity or mapped super class. I realized Symfony2 was trying to load the necessary class using the default entity manager defined by the Doctrine ORM and failing utterly. Afte...

Integrating Memcached with Symfony2

Overview This is a short tutorial to add Memcached support to your Symfony 2 application. This is actually not a really good way to add caching support to your application as your API should support multiple caching mechanisms just like Zend_Cache does; however, all I need for my application is a way to access a Memcached singleton instance and this setup satisfies that requirement. Configuration Generate a new bundle in your application source directory using the command below. php app/console generate:bundle In your app/config.yml, create a section for your bundle: app/config/config.yml acme_memcached: servers: server1: host: localhost port: 11211 weight: 25 server2: host: localhost port: 11211 weight: 75 Note: You should also add a persistence flag to this configuration; however, I am going to omit this flag to keep this tutorial simple. Once we have a format that we like, we need t...

Symfony2 SecurityBundle and FOSUserBundle integration: How does it work?

Overview A couple of days ago, I realized I needed to add some new functionality to the login process. Specifically, I needed to track all previous login attempts. Not knowing anything about the new Symfony2 SecurityBundle, I had to go through the underlying code to understand what was going on. In the process, I think got a basic idea about how the new SecurityBundle interacts with FOSUserBundle. Configuration I have a basic security configuration as illustrated below. app/config/security.yml security: encoders: Symfony\Component\Security\Core\User\User: plaintext role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: ROLE_ADMIN providers: fos_userbundle: id: fos_user.user_manager firewalls: main: pattern: .* form_login: provider: fos_userbundle check_path: /user/login_check login_path: /user/login lo...

Unexpected token "name" of value "if" ("end of statement block" expected) in "WebProfilerBundle:Collector:logger.html.twig"

Encountered this WebProfilerBundle error message when I ran the bin/vendors script to update my Symfony2 bundles. Make sure your deps file is up to date; you need to pay special attention to your version values. In this case, update your twig version to v1.2.0 as illustrated below: [twig] git=http://github.com/fabpot/Twig.git version=v1.2.0 Run the vendors script to update your bundle and the error message should disappear. You can get the most up to date deps file from the symfony-standard repository located at: https://github.com/symfony/symfony-standard/blob/master/deps

Symfony 2 + DoctrineMongoDBBundle + FOSUserBundle Tutorial

It's been a while I have not added an entry to my blog. I have been busy playing with Symfony 2, MongoDB, and FOSUserBundle for a while now so here is a tutorial to integrate Symfony 2, MongoDB, and FOSUserBundle. Objectives * Install DoctrineMongoDBBundle * Install FOSUserBundle * Create user model ** Utilize groups ** Add additional properties to user model * Create customized registration form and handler At this point I am going to assume that you have a running Symfony 2 and MongoDB installation in place already and a basic understanding of how to configure Symfony 2 services. I will also exclude view related steps from this tutorial. Setting Up DoctrineMongoDBBundle Add the following to your deps file: [doctrine-mongodb] git=http://github.com/doctrine/mongodb.git [doctrine-mongodb-odm] git=http://github.com/doctrine/mongodb-odm.git [DoctrineMongoDBBundle] git=http://github.com/symfony/DoctrineMongoDBBundle.git target=/bundles/Symfony/Bundle/Doctrin...

Exim posing as Sendmail: Fixing Sender and Return-Path headers

Exim If you are having problems changing the Sender and Return-Path headers, make sure that you are editing the right configuration file. On my CentOS 5.6: [root@server mail]# ll /usr/sbin/sendmail lrwxrwxrwx 1 root root 21 Oct 26 2009 /usr/sbin/sendmail -> /etc/alternatives/mta [root@server mail]# ll /etc/alternatives/mta lrwxrwxrwx 1 root root 23 Apr 9 07:48 /etc/alternatives/mta -> /usr/sbin/sendmail.exim [root@server mail]# ll /usr/sbin/sendmail.exim lrwxrwxrwx 1 root root 4 Apr 9 07:45 /usr/sbin/sendmail.exim -> exim I spent some time trying to figure out why my changes to the sendmail.mc file were being ignored. Naturally, Exim configuration is different than Sendmail. You need to edit the /etc/exim/exim.conf file: remote_smtp: driver = smtp return_path = bounce@domain.com headers_rewrite = apache@* info@domain.com s Don't forget the "s" at the end. See this page for more information: http://www.exim.org/exim-html-2.00/doc/html/spec_32.html...

PHP API for Solr

I finally had some time to finish my PHP client for Solr. It is still in alpha but I am planning to finalize testing for a beta release soon. The source code can be found at https://github.com/buraks78/Logic-Solr-API .