Fix The parameter “debug.error_handler.throw_at” must be defined in Symfony2

If you get this error when trying to clear a Symfony2 application cache:

$ php app/console cache:clear --env=prod --no-debug 


[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] The parameter "debug.error_handler.throw_at" must be defined.

This is the solution: delete the cache folder content and warmup de cache:

$ rm -rf app/cache/*
$ php app/console cache:warmup --env=prod

symfony-cache-clear

Ref: http://stackoverflow.com/a/27215486

How to fix no colors in Symfony2 Console Component

After updating from PHP 5.4 to PHP 5.6 I saw there was no colors anymore when running commands with the console component.

symfony-console-component-no-colors

This happend because I didn’t install php-poxis extension. So it was fixed by just running this Mac Ports command:

sudo ports install php56-poxis

symfony-console-component-with-colors

Note: If you use another version of PHP change the version number or just use php-poxis.

Ref: http://serverfault.com/a/409966

Can’t establish connection to MySQL after PHP upgrade

When you upgrade PHP there are chances that the new version is reading a different php.ini file than the previous version. You have to see which php.ini it’s reading (for example with phpinfo()) and then check that it has correctly configured the pdo_mysql.default_socket, mysql.default_socket and mysqli.default_socket options. They are probably empty:

pdo_mysql.default_socket =
mysql.default_socket =
mysqli.default_socket =

And they should have something like this:

pdo_mysql.default_socket = /opt/local/var/run/mysql55/mysqld.sock
mysql.default_socket = /opt/local/var/run/mysql55/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql55/mysqld.sock

mysql

Add Twig syntax highlight in Sublime Text 2

  1. Select the “Preferences->Browse Packages…” menu to open the folder that contains Sublime Text 2 packages.
  2. Download the Anomareh/PHP-Twig.tmbundle repository contents to a folder called PHP-Twig inside that packages folder.
  3. Move all the files inside PHP-Twig/Syntaxes folder to the PHP-Twig root folder.
  4. Restart Sublime Text 2.

You can also use the terminal to do this using git:

cd ~/.config/sublime-text-2/Packages/
git clone https://github.com/Anomareh/PHP-Twig.tmbundle.git PHP-Twig
mv PHP-Twig/Syntaxes/* PHP-Twig/

Once restarted you’ll see a new option called “HTML (Twig)” in “View->Syntax” menu. To automaticaly highlight files with html.twig extension just open one of them and select “View->Syntax->Open all current extension as…->HTML (Twig)”.

HTML-Twig-Sublime-Text-2

Fix ‘A template that extends another one cannot have a body in …’ in Twig with Symfony2

This may be a confusing error at first but it’s quite self explanatory. You can’t have any HTML text in a Twig template that extends another, not even comments.

Twig_Error_Syntax

So for example this would raise the error:

<!-- src/Acme/DemoBundle/Resources/views/Default/index.html.twig -->
{% extends 'AcmeDemoBundle::layout.html.twig' %}

{% block stylesheets %}
  {{ parent() }}
  <link rel="stylesheet" href="{{ asset('bundles/demo/css/base.css') }}" type="text/css" media="all" />
{% endblock %}

The solution: delete the HTML comment in the first line or use Twig comments:

{# src/Acme/DemoBundle/Resources/views/Default/index.html.twig #}
{% extends 'AcmeDemoBundle::layout.html.twig' %}

{% block stylesheets %}
  {{ parent() }}
  <link rel="stylesheet" href="{{ asset('bundles/demo/css/base.css') }}" type="text/css" media="all" />
{% endblock %}