Symfony Blog Bundle

HarentiusBlogBundle - bundle for a blog/simple portal (or complex, if using bundle inheritance and extension). View of this site.

As a backend, SonataAdminBundle is used. Implemented:

1. Admin panel (WYSIWYG, ckeditor), image/audio uploading, player.

2. Tags, categories, archives, tag cloud

3. Statistics

4. RSS-feed (requires modification)

5. "Smart" caching of everything, content is served very fast

To "ease the soul":

1. Tests

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.

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.

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.

Configuration

When creating a bundle, it is useful to configure it, which will be used as a library (and not only).

Of course, you can put everything in parameters, thus avoiding configuration, but that would not be kosher. =)

Proper practice is to describe the configuration in config.yml, and to extract some necessary parameters into parameters.yml:

Patterns and Architecture in Web Applications

Recently, I discovered for myself that apart from writing code and learning new technologies/using external APIs, there are things that are much more challenging.

These are things that need to be understood when developing medium to large projects. But even for relatively small projects, this is important.

Inheritance of bundles

In the Symfony framework, there is an interesting system of bundle inheritance. It is interesting because it works like object-oriented inheritance, but in reverse. When a bundle is inherited, modifications also affect the parent bundle. This is very convenient: if you don't like a certain component or you want to extend/replace its implementation, you can use the mechanism of bundle inheritance without modifying the parent bundle. However, when using the parent bundle, the new functionality will be used.

Working with class fields in Ruby.

OOP in this Ruby of yours is quite different from OOP in our proletarian php =). For example, let's take something as trivial as class fields. Despite the fact that methods are encapsulated, fields are not. (In other words, access modifiers cannot be applied to fields). All fields are protected.