Monday, May 21, 2012

Installing Sonata Bundle Error

If you get the next error when using Sonata Admin Bundle you should use the Sonata Admin Bundle 2.0 branch.

Fatal error: Declaration of Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension::getDefaultOptions() must be compatible with that of Symfony\Component\Form\FormTypeExtensionInterface::getDefaultOptions() in /var/www/ on line 186

 Clear the deps file and copy the next code


run the command php bin/vendors install -reinstall

Now everything should work.

How to Get the Most Out of Studying

Here is a playlist of videos made by a professor of physiology at Samford University in which he is explaining "How to get the most out of studying". I think this videos are very useful for everyone who is self learning or is a student.

Sunday, May 20, 2012

Symfony2 assets:install error

If you get the next error when running php app/console assets:install --symlink ./web:

  Warning: unlink(./web/bundles/framework): Permission denied in C:\wamp\www\project
\vendor\symfony\src\Symfony\Component\HttpKernel\Util\Filesystem.php line 100

Then delete folders in project/web/bundles/ then run the command and it should work.

Installing SonataAdminBundle Error

If you get the next error when installing SonataAlbumBundle:
The child node "default_contexts" at path "sonata_block" must be configured.

Then you should include this code in your app/config/config.yml file
 # app/config/config.yml
    default_contexts: [cms]
            contexts:   [admin]

        #    contexts:   [admin]


        # Some specific block from the SonataMediaBundle

Wednesday, May 16, 2012

Start learning Symfony2 help

You want to learn Symfony2? Here check the next list of websites that I found and learned from:
  1.  Darren Rees wrote a great tutorial for creating a blog in Symfony2. This tutorial helped me to get started with Symfony2, I hope it will help you too.
  2. You should read all you can from the official website because the documentation is great and there is a lot of stuff that will help you get started. Also there are some very interesting videos about Symfony2 at
  3.  This presentation made by Fabien Potencier helped me a lot, because he explains in detail how some of the components work.
  4. Symfony2 the maturity of PHP frameworks in this video Stefan Koopmanschap is explaining a lot of interesting stuff about Symfony2 that will help you understand about the framework. 
  5. A kind sir made a Jobeet tutorial with Symfony2

I hope this will help you! If you know other good learning resources please post them here. Thank you!

Monday, May 7, 2012

How to check if Entity is in an array collection of another Entity

 Check if $friend is in the friends array collection of the user

if $friend is in the array collection  method returns true otherwise it returns false

Sunday, May 6, 2012

Symfony2 Security component. How to get the user who is logged-in?

If you are using Symfony2(version 2.0.12 2012-03-19 ) and using Security component then you can get the logged in user like this:

$user = $this->container->get('security.context')->getToken()->getUser();

Symfony2 many-to-many self referencing relation using Doctrine2

Symfony2 many-to-many self referencing relation using Doctrine2

 Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL

I created this blog because I wanted to help others who are self learners like me. I spent few hours to figure out why I was getting the next error when playing with Symfony2.
Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::serialize() must return a string or NULL

I had an User entity a many to many self referencing relation. I still did not find out why I was getting the error but I found out here a way to get rid of the error. I just had to add the __sleep method for the user entity like this:

 * @ORM\Entity(repositoryClass="Acme\DemoBundle\Repository\UserRepository")
 * @ORM\Table(name="users")
 * @ORM\HasLifecycleCallbacks()

 class User
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
    private $id;
    public function __sleep()
        return array('id');

I hope this helped someone who got the same error as I did. If you have a better solution please post it here.