Every field in a form in Symfony is an instance of the parent form. To add a custom error to the form, you must access the form object of the field then add an error into it. Here is how you can embed a custom error to a form field:

$error = new formerror("There is an error with the field");
$form->get('field')->addError($error);
// You will also need to include the formerror class at the top of your file: use Symfony\Component\Form\FormError

For those who use BuddyPress on top of WordPress, you might want to update your register and log-in page by replacing the familiar WordPress login page with a branded logo themed to your current site.  Just add this code to your active child theme’s function.php file and update what I put in for “ProflicFutility.com” with your own site and logo image file name. You should put it near the end of your function.php file and remember, do NOT put in any closing PHP tags! “?>”

function custom_login_logo() {
   echo '<style type="text/css">
   h1 a { background-image: url(wp-content/uploads/prolific-futility-logo.png) !important;
   width:250px!important}
   </style>';
}
add_action('login_head', 'custom_login_logo');

function put_my_url(){
   return ('http://www.prolificfutility.com');
}
add_filter('login_headerurl', 'put_my_url');

More details of other elements you can update can be found on WordPress’s site at: http://codex.wordpress.org/Customizing_the_Login_Form.


This usually goes in the controller after checking if the form submitted is valid:

// Accessing the request vars works this way:
$formSubmit = $request->request->get(‘parentForm’);
$formEntity1 = $formSubmit['entity1'];

$formEntity2 = $formSubmit['entity2']; // This accesses other sub form object for more unmapped vars

$entity1_property = $formEntity1[0]['property_field_name'];
$entity2_property= $forEntity2[0]['property_field_name'];


Limit your CRUD indexAction so it won’t show 5,000+ records and crash with memory error:

 

public function indexAction()
{
  $em = $this->getDoctrine()->getManager();

  // LIMIT LIST to 10 (whatever you put in the 3rd field below:
  $entities = $em ->getRepository(‘MainFormBundle:SomeEntity’)->findBy(
         array(), // $where
         array(), // $orderBy
         10, // $limit
         0 // $offset
);

return $this->render(‘MainFormBundle:SomeEntity:index.html.twig’, array(
   ‘entities’ => $entities,
));
}

Here are some of the most useful references and snippets for Symfony that I encounter a lot.  I will be sure to add more to the list so I only have one place to look to copy and paste.  For the latest Symfony 2.5 Cheatsheet, click here.

– Aaron Belchamber