Symfony: ManyToMany relation with self reference

Creating a many to many relation with self reference is straight forward (see docs). However I had to edit the „getFriendsWithMe“ method to get friends for ALL users (the original user where the friends are added and vice versa: The „new“ friends of the user should also display the original user as their friend):

public function getFriendsWithMe()
{
  return new ArrayCollection(
    array_merge(array_merge($this->friendsWithMe->toArray(), $this->myFriends->toArray()))
  );
}

Without the editing, I only got the original user to show his new friends but the new friends never showed the original user as their friend.

November 17th, 2017

Using Twig 2 (within Symfony) with PHP 5.xx …

… causes the following error message: „Argument 1 passed to Twig_Filter::__construct() must be an instance of string, string given (…)“. Just update your PHP version and all should be good.
The Twig version you are currently using in your Symfony can be seen within your composer.lock file.

Oktober 23rd, 2017

PHP + Elasticsearch: No alive nodes found in your cluster

When working with Elasticsearch and php (i.e. see elasticsearch for php) it might happen that you’ll get an „No alive nodes found in your cluster“ error when connecting to the cluster from your hoster while everything works fine locally.

The (main) reason might be that you’re using the given port 9243 and the hoster doesn’t allow your scripts to connect to that host. Just change the port to the standard ssl port 443 and everything should work as intended.

August 10th, 2017

New (free) resource for stock photos

Shopify launched a new project called „Burst“ that you can add as a new stock photo resource. The service provides „Free photography for entrepreneurs“ as it is described on Burst’s homepage.

The photos come along with a Creative Commons Zero license, which means you’re allowed to basically do everything with the photos (see details on Burst’s FAQ). Tho you’re still allowed to credit the author 😉

Original source: techcrunch.com

April 4th, 2017

Mac Apache not starting because of PHP standard module

If you have a problem with Apache not starting although there’s no error log entry (and sudo apachectl configtest also doesn’t help), try
sudo apachectl -X
That way the debug mode is enabled and you get to see every problem that prevents Apache from starting. Even if it’s a PHP warning that is caused by the standard PHP module:
Warning: PHP Startup: Unable to load dynamic library '/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/curl.so' - dlopen(/usr/local/php5/lib/php/extensions/no-debug-non-zts-20160303/curl.so, 9): Library not loaded: /usr/local/php5/lib/libcurl.4.dylib

If you encounter that warning / error, comment the php5_module line out (to find in /etc/apache2/httpd.conf):
#LoadModule php5_module libexec/apache2/libphp5.so

Februar 24th, 2017

macOS Sierra: Upgrading PHP to 7.x

For those of you who want/need to upgrade PHP to version 7 and keeping it simple: There’s a neat tutorial on coolestguidesontheplanet.com

Just run the following command on your terminal:
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1

After you upgraded to PHP 7 you need to update your PATH and save it in your ~/.bash_profile:
export PATH=/usr/local/php5/bin:$PATH;

Check your PHP version on the terminal:
php -v

Februar 18th, 2017

The reactive programming paradigm

I think I’m getting old. There’s a new programming paradigm floating around (for four years) which I’ve barely heart of. And now that I know it exists (by „stumbling“ over it via learning Angular 2) I can’t imagine coding without it ever again. There’s even a manifest (see: http://www.reactivemanifesto.org/).

Reactive programming focuses on the change of a state over time not just on the state in that particular moment.
The inevitable advantage of that kind of programming is that we actually don’t need to take care of the new state but let the application handle everything necessary (like seen in Angular 2’s Two Way Data Binding).

As debugging is also affected by the paradigm it was very unfamiliar to work with streams and observables at the beginning. You can’t console.log your way from everywhere in the application. You have to follow the „flow“ (i.e. stream) to get the desired information. But once you got used to it, working reactive feels more natural than the old approach.

Februar 7th, 2017

Relaunch

Relaunched the site – and the blog.

Januar 12th, 2017