Symfony2: Forms and Ajax
Making Ajax calls is a trivial task nowadays for any web developer, and I'm sure it's no enigma for all of you how to do it using your favourite Javascript library or framework like jQuery, Angular, Backbone, you name it.
But how do we handle these requests in the backend? More specifically, how should we write our controllers to take full advantage of our preferred framework, Symfony 2 in my case, and create a great UX for our consumers (with errors displayed nicely and effortless) and a great feeling for our colleagues with whom we share the code (by using status codes and promises).
10 Awesome CSS Tips and Tricks
This is a collection of CSS tips, tricks, and fixes, or whatever you want to call them, that I stumbled upon along the way. I have to say from the very beginning that you can find most of these, if not all of them, familiar. On the other hand, I really hope that some of you might learn something new from this post. So let's begin.
How to Add Share Buttons to Symfony2 Generated Web Pages
Some projects require you to add social share buttons for their pages. I'm gonna show you a simple way to do this using the Socialitejs JavaScript library.
First you're gonna have to download the Socialitejs library, save it to your bundle Resources/public/js
folder and publish the assets.
If you have a general layout that is inherited by all your specific page templates (like it's usually the case), just add the share code in it like so:Read more
How to (Easily) Debug a Rails Application
Hello all you party people! This article will show you how you can easily debug your Rails code.
If you're using the default Rails Rack server, Webrick - the best debugging tool I've been able to find out there is pry. Its use is pretty straightforward:
First off you'd need to add the pry
gem to your Gemfile
. Since this is used for development purposes, it should be added in the :development
group:Read more
Symfony2: Gedmo Softdeletable Doctrine Entities With Unique Index Columns
There is a problem when using the SoftDeletable Doctrine extension for entities that have some unique index columns. The most obvious example is User entities. An User has at least one column that needs to be unique (username and/or email). When soft-deleting an User the actual record will stay in the db table. Now if you try to create a new one with the same username/email, the validation will pass (doctrine will not see the existing soft-deleted one) but the database layer will not be able to save the new record:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ... for key …
How to Convert Web (HTML) Pages into PDF Files
Here's a collection of steps needed to create PDF files directly from HTML web pages.
If you're working on a Ubuntu Linux machine, the first thing you need to do is to install the WKHTMLTOPDF
library, by running the following commands into your terminal:Read more
Symfony2: How To Get The Label For A Specific Form Field In Twig
If you need to render the label
value for a specific field without rendering the entire HTML label
element (e. g. to use it for a placeholder), you can do it by using the label
form variable:
{{ form_widget(form.fieldName, {'attr': {'placeholder’: form.fieldName.vars.label}}) }}
Symfony2: How to Check If a Form Field Has Errors in Twig
Sometimes you need to check if a field or even the entire form has errors before rendering them (e.g. when adding an errors container). Here's the code snippet that allows you to check for the errors form variable:
{% if form.vars.errors or form.fieldName.vars.errors %} ... {% endif %}