TYPO3-Extbase: Redirect exceptions to 404-page

Sometimes your Extbase-extension crashes and throws an exception, especially when it tries to fetch entities which were hidden or deleted . As for development this might be acceptable, for live-environment it is not. But hey, a solution to this problem is near: Catch the exception and pass it into the regular TYPO3-error-handling (which is normally a 404).

Continue reading TYPO3-Extbase: Redirect exceptions to 404-page

Symfony Live Berlin 2014

In October I went to the SymfonyLive in Berlin, I was pleasantly surprised how high the niveau of the speeches was. It was my first time there, in the years before I was only attending some general fairs like the Internet World or the TYPO3-Bootcamp, where I found some lightweighted CSS-talks :)

But here at SimfonyLive my tech-heart jumped higher, because all the topics seemed quite interesting to me when I read the program. After all there were some better speakers and some worse (as always), but these were my favourite ones:

Thorsten Rinne https://twitter.com/ThorstenRinne
He talked about a whole refactoring and redesign of the code and infrastructure of Yatego and how they used Elastic Search for that, very interesting talk

Benjamin Eberlei
http://qafoo.com/resources/presentations/symfony_live_berlin_2014_2014/feature_flags_with_symfony.html
How does Facebook roll out or test certain features to a small group of people? Tadaaaah, it’s Feature Flags!

Nils Adermann, creator of composer (thanks for that, you’re a genius)
http://naderman.de/slippy/src/?file=2014-10-31-Efficient-Use-of-Microservices.html
Nils presented a nice way to asynchronically work on datastreams. Wow, I didn’t know you could go so far with PHP. For example a curl-call to a 1-mio-item-json which never has to be persisted in whole

Dustin Whittle: Scaling PHP
https://speakerdeck.com/dustinwhittle/scaling-php
MemCached, Workers, Doctrine-Cache, http-cache: a solid roundtrip to all the performance-approaches in the PHP-world.

 

 

Useful tips for symfony2/doctrine optimization

In the LinkedIn-symfony-group I stumbled upon a very useful link:

http://labs.octivi.com/mastering-symfony2-performance-doctrine/

This is a must-read for all doctrine-beginners, I wish i woud have read it when I started… Here are the points in short:

  • use the Symfony Profiler toolbar
  • avoid object hydration
  • use IDs for referencing rather than whole object
  • use update-statement
  • use lazy collections
  • never load entities in a loop

More infos can be found in the article.

Connect remote vagrant mysql-db via Navicat

My favorite mysql-client for Mac is Navicat, mostly because of its synchronizing feature. So when you want to connect your local vagrant-mysql-db, you have to use a SSH-Tunnel:

Tab “General”

  • hostname: localhost
  • port: default (3306)
  • username: root
  • password: [password you set up in your vagrantfile / puppet-settings]

Navicat connection

 Tab “SSH”

  • hostname: your local domain / url, alternatively the IP-address (192.168.50.x)
  • port: default
  • username: vagrant
  • password: vagrant

Navicat SSH-Tunnel

 

That’s it :)

 

TYPO3: open fancybox / lightbox with second image

The TYPO3-Extension cl_jquery_fancybox enhances the click-to-enlarge capability of with the beautiful “fancybox-effect”.

Sometimes you do not only want to enlarge the same picture, but you want to open a different image in the lightbox (thumbnail pictureOne.jpg opens picure2.jpg). You can add a file-link, but unfortunately the lightbox-effect disappears :(

Just add this line of code to typoscript and all images with a filelink get a lightbox-class:

(worked with TYPO3 6.1.6 & cl_jquery_fancybox 3.0.6)

Truncate text in Twig & Symfony 2

In the core symfony / twig do not have a simple truncate-text-function, like substr() in PHP. Therefor you have to activate the Twig-Text-Extension:

Now you can easily truncate as you like:

If you want to preserve whole words, you have to set the 2nd parameter:

With the 3rd parameter you can override the default seperator ‘…':

 

Thanks Scott :)

Store Symfony-Sessions in the Database

On my recent project I used cloudhosting www.cloudcontrol.com for easy scaling. Unfortunately they don’t support synchronized filestorage, so when you store a session on one machine, on the next request it is gone :(

There is a quite simple workaround, just store your sessions in the database:
http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html

The drawback is a (possibly) pretty huge database, so make sure you have some kind of garbage collector that cleans the entries from time to time.

PHP-Traits in Symfony: Add timestamps and more to tables magically

Say you want to add a logging preprocessor to some of your classes. Either all of these classes have to inherit some kind of logger-class, or you have to copy the logging-call multiple times. Not anymore! PHP 5.4.0 introduced Traits, a wonderful way to inject code into your classes without using inheritance.

A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way.

Some guys in the Symfony-community prepares some great traits:

  • Timestampable
  • Loggable
  • Translatable
  • Sortable
  • Tree

Go check them out:

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/timestampable.md#traits

iPhone traffic sniffer

If you always wanted to know “What kind of data does this crappy facebook-iphone-app send all the time?” then this might be the right way to find out:

http://blog.jerodsanto.net/2009/06/sniff-your-iphones-network-traffic/

Basically you have to install Paros, a proxy to sniff your iPhone traffic. Then you have to set the URL of your local mac-ip on the iPhone, that’s it.

Happy sniffing :)

 

TYPO3 settings for multi-domain site

Whenever you have your TYPO3-system running on several machines, like local, stage and dev, you have to change the settings in your localconf.php, at least in the older versions of TYPO3.

Since TYPO3 6.0 you have to set it in the file AdditionalConfiguration.php, for this one is not being overwritten like LocalConfiguration.php.

Simply check the host you are on and set the db-credentials accordingly: