Dumping Results With PDO

With PDO, there is a native method to dump the result of a query.



This can compliment the debug method in Twig itself :

{{ dump(result) }}


In Symfony2, you can use Doctrine to dump also:


2015-01-27 14:01:57 0 Commentaires

Debugging With Twig

Rendering HTML in twig template with Twig

By default whenever you try to pass an HTML string to Twig, it applies a function like html_entities(),
opening bracket < will be displayed as
&lt; , so if you want to render the HTML you should use the raw filter like this:

{{ html_string| raw }}

Echoing an array

{{  dump(products) }}


2015-01-21 00:00:00 0 Commentaires

Improve Your OOP Skills With Symfony

If you've been programming in php for several years, chances are you've come across OOP programming because your application has grown in complexity.

Coding in OOP is a very good move (but not that easy at the beginning). And at the end you'd feel the benefit of code reusing.

What is code reuse?

If you develop more than 2 web applications, you will find code reusing time saving.

There shoudl be common stuff to share like user login, form validation to name a few.

But the difficulty is that you may work in two different environment and you will need to modify the first code in the second application. Unless you are comfortable with high level OOP programming (abstract class, interface, polymorphism, dependency injection, namespace, class autoloading), it is inevitable that you will alter the code.

In fact writing reusable code is not that easy, it needs knowledge of advanced OOP concept.

The best way to start is to download a well known API such as FOSUserBundle and see under the hood. It uses lots of abstraction.

Abstraction is the keyword, this mechanism allows you to write generic methods to be used consistently in different frameworks.

Before you can write reusable code (that you can share as open source), first try to master the key concept of OOP programming such as interface, polypmorphism and design pattern.

Key OOP concept to work on

Here is what i'm working on to master OOP:

Interface and abstract classes

Those two have similarities, abstract classes can only be inherited, but can contain non abstract method, while interfaces are 100% abstract classes. Interface are quite bizarre at first, because they define method ans their signature, but there is no code in the method ! They tell you that using interface can allow you to function in different environment, for example using interface allow you to connect to Mysql as well as PostGrest, or SQLite. Okay, how?



In Java, which is a strongly typed language, (a string is a string, a number is a number and not a string), the polymorphism mechanism allow you to manipulate different type of object.

Design pattern

Design pattern are recipes to solve a problem. For example the singleton design pattern, makes it impossible to instantiate more than once a class. Why? if you don't want to mess up with lots of object and manage memory well then use it. Factory is another one that'll be useful, it is a method of object instantiation without using the constructor of a class, in fact you delegate the instantiation of a class to another class, why? if you one day rename the class or change the class, then you'll only need to do it in the factory class, that will save you time !

2014-12-24 16:12:31 0 Commentaires

Component To Know Well When Learning Symfony

Even though you'll want to code without using a OOP framework I encourage you to first code with a framework, you'll learn a lot about the best pratices, then you'll be comfortable when you want to do thing without one.


Here are the essential component to know well when you learn Symfony :


it is the most important component to know because it is responsible for mapping a url request to a controller, there are different ways to do it, using yaml in the routing.yaml fiel, or annotation within your controller methods, or in XML or even directly in PHP.

Things get complicated when you have parameters in your urls (most of the time)


a route that you'll use to match this request is


path: /view/{id}

defaults: { _controller: AcmeStoreBundle:Default:view}

or in annotation

@Route("/view/{id}", name="acme_store_view")


Form component

The Form component is tricky, because behind its simplicity, there are a lot of thing done, and the day you want to customize things, difficulties will arise because this complexity usually is hidden, so take an in depth look at the documentation and test test test!

One difficult thing i met is how to customize the forms fields with the glyphicons of Bootstrap.

2014-12-24 10:12:04 0 Commentaires

Walkthrough The AngularJS Tutorial

I Assume this is for Windows 7

If you have difficulties doing the angulars JS toolset on the tutorial from this page :


Then these informations may interest you

First you've got to install Git, the versionning tool, and set the path varaible. This page is helpful.

Once you have set the path you must close all active prompt and restart again otherwise the new path will not be set.

Download nodejs installer on the given path, then run it. After install is complete, go to the angular-phonecat folder to do the following thing:

npm install

It will install the needed packages or dependencies. Toi make this work you must create the npm folder in the AppData such as:


you may run explorer as an administratot to do this but not sure it's needed.

Don't worry if you don't succeed, these are only tools, you can do the tutorial with a text editor such as SublimeText which is recommended for writing AngularJS scripts.


The rest of the tutorial

2014-10-31 16:10:12 0 Commentaires

Transitioning From Procedural Programmer To OOP Programmer

Recently i went through a lot of changes in my computing life.

After spending 5 years coding in procedural PHP i am going full throttle for OOP PHP.

I enjoyed PHP very much these years, from the day i learnt how to connect to a database, to more recently how to scrape a website using curl via proxies, i've learnt a lot, still a lot to learn.

Proof is i spent a month learning Java EE, using Eclipse, and I must admit that it's time to become a better developper. Embracing OOP programming involves learning a lot of new paradigm and habits.

Use a real IDE

Like Eclipse. I have used SublimeText, and was very happy with it, but if you are coding in a OOP manner, this software doesn't fit so well. I needed a software that could parse libraries and have auto completion, access to documentation, do more advanced stuff.

Learn versioning !

At one point in time, you'll be very annoyed with the different folders storing your different script versions. Isn't great a software can do the version management for you? thus eliminating the risk of messing up with your code on a production site ! This is very important if you work in a team.

Think in OOP

Of cours ! But OOP involves concept such as Dependy injection, Inversion of Control, writing unit test, design patterns, loose coupling, infamous OOP concept such as inheritance, polymorphism, interface, Exception.

That's only the beginning !

After you get your foot into OOP, you'll have to be familiar with software building. I'll explain later what software building is. You'll need to grasp the concept of continuous integration, Agile ans Scrum. And with that you'll be familiar with Jenkins, which is a continuous ( CI) integration server.

The process of building a software includes various testing of your software, functional testing and integration testing, for example testing a web interface, and have these test automated to reduce the isk of error. CasperJS or Selenium are the most popular choice these days.

So, i am in a new journey to the land of coding, and this is simply fantastic. I'll share my learning on this blog with you.

2014-10-27 23:10:42 0 Commentaires