New blog

It’s been a long time since I blogged.
Now I’m moving to a new blog hosted on my own server

Join me there!

Leave a comment

datepicker with custom types in symfony 2.1

Hey guys
So we recently have started working on a new project and I’m still learning things about symfony2
Each time I learn something about it I love it more and more
So yesterday(It’s 3:17 AM right now :D) I tried to created a date type that works with jquery datepicker and let us chose different format(For I18N)
I will tell you what you should do
First you need to create a file in yourBundle/Form/Type called DateType
The content of this file is going to be like this

public function buildForm(FormBuilderInterface $builder, array $options) {

$javascriptFormat = str_replace(array('yyyy', 'MM', 'dd'), array('yy', 'mm', 'dd'), $options['format']);

$builder->setAttribute('javascript_format', $javascriptFormat);

public function setDefaultOptions(OptionsResolverInterface $resolver)
'format' => 'yyyy/MM/dd',
'widget' => 'single_text'

'format' => 'string'

public function buildView(FormView $view, FormInterface $form, array $options)
$view->set('javascript_format', $form->getAttribute('javascript_format'));


Look for word “your” to see what you need to change
So basically we make a type that is child of date type(since in getParent we return date type name)
Next thing is to make some customization in form themes
You must read this part of documentation in symfony2 site
How to customize Form Rendering

So now you have a file in your-bundle/Resources/views/Form/fields.html.twig
Add this code to it

{% block date_widget %}
{% spaceless %}
{% if widget == 'single_text' %}
{% set attr = attr|merge({'data-date-format': javascript_format}) %}
{{ block('form_widget_simple') }}
{% else %}

{{ date_pattern|replace({
'{{ year }}': form_widget(form.year),
'{{ month }}': form_widget(form.month),
'{{ day }}': form_widget(,
})|raw }}

{% endif %}
{% endspaceless %}
{% endblock date_widget %}

It’s the same code as the one used in symfony core but with 1 more line which inject an attribute to the field to know what the format of the date is

The next step is to add your_date type to the services
I only have the yaml format so for xml you should use yaml to xml

class: your-bundle\Form\Type\DateType
- { name: form.type, alias: your_date }

In the layout or somewhere in your template you need to add this code

$(document).ready(function() {
$('[data-date-format]').each(function() {
numberOfMonths: 1,
dateFormat: $(this).attr('data-date-format'),
showButtonPanel: true

Now you’re all done
You can use your_date in the builder like this

public function buildForm(FormBuilderInterface $builder, array $options)
->add('beginDate', 'your_date', array('format' => 'dd/yyyy/MM'))
->add('endDate', 'your_date')


In the future I might add the data transformer so it could be even used for Persian calendar date
Have fun
P.S: I didn’t enter the details because I’m really tired so if you have any question about any part don’t hesitate to ask

, , , , ,

Leave a comment

New features coming

Hi guys
After a long time I checked all the comments and fixed the problems that you guys reported to me
1- problem with deleting comments in wp 3.2
2- showing fields when the user is logged in

Right now I’m really busy as I have to work 20 hours per week and have like 20 hours of University classes :S
So what are the next features for the plugin to keep it up with nice features of wp 3.2 😄
1- Suggested in comments by Søren Sommerglæde
I will add a new field in the table which you edit the fields which can let you select a type for the field
2- It’s not a feature it’s like more cleaning up the plugin
I will change the name of the buttons and the look of the table to make it easier to unserstand
3- If possible I will add a more about this user link(or something shorter) to where the comment appears for visitors so other visitors can see the info of the user
4- If the feature #3 is added the will be an option to say which fields will be shown for the public and which will be only for the admin

I hope you enjoy this plugin 😉

Leave a comment


Hi everyone
Today Im gonna show you my latest plugin(This one is in jquery:D)
So what does this plugin do?
It’s not really a plugin but an object that your form extends it then you can duplicate your fields remove them or add n number of them
Let see the object code

var jDupIt = {
fieldsElement: null,
initialize: function() {
newElement = $('#outer-fields-div').children('div.fields-div:first').clone();
this.fieldsElement = newElement;
addOne: function() {
newElement = this.fieldsElement.clone();
bindAddOne: function(clickElement) {
formObj = this;
bindAddN: function(clickElement, inputElement) {
formObj = this;
for (i = 0 ; i < $(inputElement).val() ; i++)
bindRemoveCurrent: function(clickElement) {
$(clickElement).live('click', function(){
$(this).parents('div.fields-div').slideUp('slow', function(){$(this).remove()});
bindRemoveLast: function(clickElement) {
$('#outer-fields-div').children('div.fields-div:last').slideUp('slow', function(){$(this).remove()})

And here is the html code

<form id=”factor-form” method=”post”>
<label>Factor Num: </label>
<input name=”num_fac” type=”text” />
<label>Address: </label>
<input name=”address” type=”text” />
<div id=”outer-fields-div”>
<div class=”fields-div”>
<label>Referencia: </label>
<input name=”references[]” type=”text” />
<label>Precio </label>
<input name=”prices[]” type=”text” />

<img src=”images/cross.png” width=”16″ height=”16″ border=”0″ />
<input type=”submit” value=”ok” name=”submit” />
<!– Controls –>
<div id=”controls”>
<div id=”add”><a><span>Add One</span></a></div>
<div id=”remove”><a><span>Remove</span></a></div>
<div id=”add-n-div”>
<div id=”add-n”><a><span>Add</span></a></div>
<input id=”add-n-num” type=”text” size=”4″ /> products
<!– /Controls –>

Be careful

You can name every element as you like but 2 of them

<div id=”outer-fields-div”>
<div class=”fields-div”>

The first one is to know where the dynamic fields are and the second one is to know which fields to duplicate

Which means the second one contains the dynamic fields and the first one contains nothing or one or more blocks of second one

So what should you do to use the object?

element = $('#factor-form');
jQuery.extend(element, jDupIt);

First your form extends jDupIt then you bind the buttons or links to the actions

element.bindAddN('#add-n', '#add-n-num');

(#add-n-num is the id of the input that indicates the number of times that you want to duplicate the fields)


Do not forget to call element.initialize since it’s necessary
I hope this plugin be helpful for you

Leave a comment

Facebook vs. Google+

So as you know it’s been a long time that facebook and google had some fight about the email and social network system.
So google finally has made his move and launched the invite-only testing phase to test it’s new system
I was amazed by it
The interface and the way you do things in Google+ is totally different from Facebook
Lately I was really unhappy about the problem with the Facebook(When you watch videos from YouTube and then decide to see a pic after opening the pic all the videos restart and start to play again)
Google offers lots of things that Facebook hasn’t offered even after 7 years and one of them which I hate it so much is the limit in status that Google seems to have more limit or not any limit at all(I have tried with more than 3300 characters and I guess it’s unlimited)
So why Facebook gonna lose to Google+?
We can’t deny the quantity of the people that are using Facebook right now(more than 500 million)
But Google is like a monster that has gotten over the whole internet and there is no way for Facebook which is a one service website to challenge such a monster
And the other thing is if you have a Gmail(You probably have) then once Google+ is public you will see the notification and everything needed for Google+ in the bar at the top of the page when you are using Google to find what you need
Soon you will be able to see why I love Google+ so much
Right now just there aren’t lots of people in Google+ from my friends but once it is public I’m not going to use Facebook anymore:)

Leave a comment

Best hosting

Well since I introduced you the svn server so it’s better to introduce you to a good pricing shared hosting too
It’s been more than a year that I have my site hosted by this hosting and I’m really happy about their support and service
The only bad thing about this hosting is the domain price since in comparison to other hosts it’s really high($12 + tax)
So what I suggest you is to host your domains in a server that have a good pricing for domains and the change the dns to this host
The management of external domains is really really easy and I’m sure you will be happy with their services
Host your Web site with iPage!

1 Comment

Best svn server

Hello everyone
Today I’m going to introduce you to the server that I have been using for a year and I’m really happy with them(Well recently they had lots of upgrades so they sometime were down due to these upgrades)
But for my personal website which has like 700 800 unique visitors per day I’m really happy with their service(And the company which I work in, uses this server for more than 20 large project)
It’s called Springloops(Don’t ask what it means:D)
So what’s good about this server
Once you have your project uploaded in this server you can give your server ftp access(It can be a shared hosting!!) and with a once click you have the whole project in the given directory in your host
I know the prices seem to be a little rare but I suggest you the GARDEN plan
You can get a free plan for minimum features to check whether it meets your expectation or not(And even 28 free trial days only through this link -normally it’s 14 days-)
Just check it out
They won’t ask you for any credit card for the trial so don’t be afraid and use it;)

Leave a comment


I always hated the domain business and never liked it
When I hate it when someone buys a domain and doesn’t use it and just waits for someone to pay him a large amount of money
And now I just wanted to check is is still free or not
And guess what!!
It was registered in January the month that my blog got more active(I had this blog from September 2010)
I would be happy if it was a page with some content but it’s not and I’m sure that person is waiting for someone to pay him good for the domain
Well I hope he waits until the end of his life 😀

Leave a comment

Showing custom comments saved values to visitors

Hi everyone
It’s been a long time since I wrote something
Due to requests for showing the custom fields in the template I searched a little bit and finally found the easiest solution
So what should you do?

First of all
Go to you template directory (in default template it’s “wp-content/themes/twentyten”)
Open comments.php and search for “wp_list_comments”(Don’t search with quotes :P)
Do you see the “something” in wp_list_comments( array( ‘callback’ => ‘something’ ) );?
That’s the function that will be overwrite the default template for comments
If it’s not there add it and instead of something write the name you like
Now open functions.php
If you haven’t changed anything in comments.php so search for “something”(the name of the function)
Now you you should add this code to this function wherever you want(put it in different place to see where it will appear-at the beginning it will be before author and at the end after the reply link-)

The function

$CComment_fields = array_filter(explode(",", get_option('CComment_fields')));
foreach ($CComment_fields as $CComment_field){
$CComment_field_arr = explode(";CuCo;", get_option($CComment_field));
$CComment_field_desc = $CComment_field_arr[0];
$CComment_field_active = $CComment_field_arr[1];
$Comment_field_value = get_comment_meta(get_comment_ID(), "CuCo_".$CComment_field);
if ($CComment_field_active == 1)
echo $CComment_field_desc.' : '. (($Comment_field_value[0] != '') ? $Comment_field_value[0] : '-');

Do you see this line “echo $CComment_field_desc.’ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);”?
It’s the part that prints each of custom field and it’s value
Just play with it as you please(add class, id or whatever you want)
For example
echo ‘
<div class=”cc-field”>’ . $CComment_field_desc .</div>
. ‘ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);
I hope this helps
Thanks for all of the comments about this plugin 🙂

, , ,


symfony & svn & Linux/Unix

I know lots of people use symfony in Linux or Unix operating system as we all know right now there isn’t any free program to use like tortoise in windows.

Yesterday I finally found a good solution.

This bash script simply search through all the files that are not under version control and it simply ignores the files under cache, log and config folder.

I hope it helps you out.
(make a file with sh extension the chmod it to 755 and put it in the parents folder to avoid adding it to the version control)

svn st | grep “^\?” | grep -v config | grep -v cache | awk “{print \$2}” | xargs svn add $1

, , , , , , ,