Boxing Clock

Boxing Clock
Boxing Clock

It is a simple boxing clock where you have 3 choices:

  • 10 seconds for fight and 5 seconds for break;
  • 2 min for fight and 1 min for break;
  • 3 min for fight and 1 min for break;

Of course the first choice is just for demonstration… Another choices are available to train or to fight. You will listen a sound after determined time!

Label Option

… However, a better practice is to build the form in a separate, standalone PHP class, which can then be reused anywhere in your application…

Source: Symfony Form

namespace appbd\AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PersonType extends AbstractType
{
  public function buildForm(FormBuilderInterface $builder, array $options){
   $builder->add('firstName');
  }

  public function setDefaultOptions(OptionsResolverInterface $resolver){
   $resolver->setDefaults(array('data_class'=>'appbd\AdminBundle\Entity\Person'));
  }

  public function getName(){
   return 'appbd_adminbundle_person';
  }
}

To modify a label, all you need is:

$builder->add('firstName', null, array('label'->'First Name'))

How to use raw SQL queries in Symfony2

I wrote a long query that involve more than three tables to show correct data. The more I was writing the SQL query using the similar code below, more problems I was facing:

       $product = $this->getDoctrine()
        ->getRepository('AppBundle:Product')
        ->find($id);

So to not waste more time, I decided to use raw SQL queries in spite of I shouldn’t use. There is a site that helped me a lot.

How to sort findAll method

When I was developing a Symfony2 application, I was faced to next question: How do I sort all records ordered by ascending first name? The solution is:

  1. create a class UserRepository;
  2. create a method findAll;
  3. inside method findAll, use function findBy and the arguments to sort.

Source code’s class UserRepository

class UserRepository extends EntityRepository{

  public function findAll(){
   return $this->findBy(array(), array('firstName' => 'ASC'));
  }
}

Don’t forget to tell User entity to look for queries in the UserRepository.

/**
* @ORM\Entity(repositoryClass="app\UserBundle\Entity\UserRepository")
*/
class User{
 ...
}