Iteration over a time period in PHP

Repeatedly had to work with a list of dates on php (by days, for example) if there is a start and end of the period ($dateStart, $dateEnd). For example, to synchronize working/non-working days for the DatePicker from jQueryUi with the backend. Or if you need to display reports by days.

I suggest several options for solving this problem, both the most obvious way and a more elegant way (as it seemed to me).

Symfony Widgets Bundle

Widgets Bundle - a bundle for easy widgets management. (Supports only widgets which require only client-side code for displaying). Includes both client side (for displaying) and admin side (adds admin classes and has a SonataAdminBundle dependency) functionality.

Can be used (for example) for adding counters, banners, advertising network codes (google adsense, etc).

Was created during this blog has been developing.

Caching Symfony controller

During developing this blog I invented one more bicycle for Caching Symfony controller. But first of all lets see how did this task arose.

For example, I have a list of categories, archives and tags on a sidebar. It is relatively easy to get last one (one query), but much harder to get list of categories and archives. For getting categories, we need to select trees (categories can be nested) and using subqueries inside queries get number of articles in every category (result is a little bit monster). For getting the archives list, we need iterate over all articles and gather list of years/months. All this actions isn't very sophisticated, but it is better to avoid them.

Pencil

Pencil - convenient open-source free prototyping tool for creating mockups. It is suitable for creating any user interfaces, but we will consider creating web interfaces.

Can be installed as a firefox plugin or as a standalone application (in this case, firefox was installed as a dependency).

Convenient for quickly creating a website page schema, so as not to draw on paper. It also allows you to add interactivity by linking pages. A simple and fast learning tool.

We will explain the installation and show an example of use.

Increase web server performance: we put nginx in front of apache

In one of the notes we described how to configure nginx + php-fpm. But nginx can be used in a slightly different way. For example, if you don't want to completely abandon apache, but you want to speed up the web server. (Perhaps you have implemented a complex redirect system that you don't want to port to nginx).

In this case, a possible solution is to use nginx only for serving static files (images, css, js, etc.). Other requests (to the php engine, for example) will still be redirected to apache (assuming you already have a site configured to work with it). To do this, configure nginx to serve static files, and proxy all other requests to apache. (In this case, you can do without php-fpm).

Localization of numeric/monetary data

When developing a medium to large project, there is a problem with localizing numeric/money data. In this note, I will talk about the difficulties of using the Symfony framework, Sonata Admin Bundle, and the client-side. But first, let's discuss the essence of the problem, as it is not very obvious at first glance.

So, let's say we have a project that renders numeric/money data on the server side (php/template engine). They should be displayed according to the set locale. The user can enter data (in their own representation). At the same time, the data can be processed on the client side (javascript). For example, in most European countries, except for the UK and Ireland, the decimal separator is a comma while in the UK and Ireland it is a period. Naturally, a user from Germany will enter data with a comma separator.

Geniuses and Outsiders. Why some have everything and others have nothing - Malcolm Gladwell

About the book "Geniuses and Outsiders. Why some have it all and others have nothing" by Malcolm Gladwell, I found out by accident, from the comments on geektimes. I decided to share my impression by writing a short review.

Firstly, I must say that this book is not a universal guide "how to achieve success". On the contrary, the book talks about how difficult everything is in this world (which, by the way, may only be doubted by constant reposters of "success diaries").

First of all, it discusses the enormous influence of the environment on great personalities. No, don't think that they were just lucky. In reality, it's not enough to just have the necessary set of personal qualities, just as it's not enough to simply end up in a favorable environment. All of this has to happen simultaneously. The author analyzes the personalities of Bill Gates, Bill Joy, and others, provides historical examples.

Customizing login form (using FOSUserBundle as an example)

The simplest way to customize the login form in FOSUserBundle is to use the mechanism of bundle inheritance. (Assuming that in the future it will be necessary to modify not only the login form). Let's show an example of such customization using bootstrap.

Fixtures. AliceBundle

In the previous article, we learned about fixtures in the Symfony framework, as well as the DoctrineFixturesBundle. Let's take a look at another useful bundle for working with fixtures - AliceBundle (a wrapper around the alice component).

Fixtures. DoctrineFixturesBundle

Fixtures (Eng. fixtures) - a very useful development tool. Essentially, it is just a set of test data used in dev mode. They are typically not used in prod mode (for production, Data Migrations are usually used).

There are several convenient bundles for working with fixtures in Symfony. The first one is the basic DoctrineFixturesBundle, which is dedicated to this article.

Roger Penrose - The New Mind of the King

This book became a kind of discovery for me. But first, a little bit of "poetry". =)

It just so happened that I love complex reading material. However, one should be very careful in this regard, as "complex reading material" can be at the level of Coelho (may all his fans forgive me, but it is difficult (for me) to find another bright example), or it can be something that truly changes you, for the better, towards less entropy (this was said under the impression of the book by Penrose). So what is the difference?