Archive for the 'Symfony' Category

Admin Symfony : custom filters

Mardi, juillet 27th, 2010

How to add custom filters in admin generator in Symfony ?

Follow the guide ! http://www.xaviergodart.com/blog/2009/03/26/custom-filters-dans-ladmin-generator-de-symfony-12/

Symfony : admin objets Propel arborescents

Mercredi, février 24th, 2010

Un excellent tuto, pour gérer des objets Propel arborescents avec admin sexy :

Merci à Tim !

Compare Propel and Doctrine

Mercredi, décembre 2nd, 2009

A good overview about these 2 ORM is available here :

http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/

Symfony Datagrid component

Lundi, avril 6th, 2009

A very good and well documented Symfony Datagrid component (plugin) :

http://www.symfony-project.org/plugins/sfDatagridPlugin

sfDataGrid

Symfony ProjectConfiguration.class.php lib path

Mercredi, février 25th, 2009

In need to tweak config/ProjectConfiguration.class.php file in order to import a project to a sandbox symfony workspace.

The path to sfCoreAutoload was never good between web and cli symfony.

Here is the trick :

if (!@include_once ‘./lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php’) {
include_once ‘../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php’;
}
sfCoreAutoload::register();

Bug dans admin sfGuardUser

Dimanche, janvier 25th, 2009

Un bug semble s’être glissé dans le formulaire d’administration du plugin symfony sfGuardUser.

“The item has not been saved due to some errors.” (when you try to save the form)

The fix :

It would seem the cause of the issue is on line 44 of the sfGuardUserAdmin form class.

Removing that solves the problem.

Mark required field in a Symfony Form (sfForm) with an asterisk

Jeudi, janvier 22nd, 2009

How to mark required / mandatories fields in a form based on sfForm ? (solution based on Dark-IT post, adapted and tested on Symfony 1.2)
Add in your lib/form directory a class name : RegistrationForm.php (you can name it as you want of course)

class RegistrationForm extends sfForm
{
public function configure()
{
// …
}

public function render($attributes = array())
{
$formatterObj = $this->widgetSchema->getFormFormatter();
if(!is_null($formatterObj)) {
$formatterObj->setValidatorSchema($this->getValidatorSchema());
}
return parent::render($attributes);
}

public function __toString()
{
try
{
return $this->renderUsing(’Registration’);
}
catch (Exception $e)
{
self::setToStringException($e);
// we return a simple Exception message in case the form framework is used out of symfony.
return ‘Exception: ‘.$e->getMessage();
}
}
}

Add another class in your lib/form directory : sfWidgetFormSchemaFormatterRegistration.php

class sfWidgetFormSchemaFormatterRegistration extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = “\n

%label% %error%%field%%help%%hidden_fields%”,
$requiredTemplate= ‘

*’,
$validatorSchema = null;/**
* Generates the label name for the given field name.
*
* @param  string $name  The field name
* @return string The label name
*/
public function generateLabelName($name)
{
$label = parent::generateLabelName($name);

$fields = $this->validatorSchema->getFields();
if($fields[$name] != null) {
$field = $fields[$name];
if($field->hasOption(’required’) && $field->getOption(’required’)) {
$label .= $this->requiredTemplate;
}
}

return $label;

}

public function setValidatorSchema(sfValidatorSchema $validatorSchema)
{
$this->validatorSchema = $validatorSchema;
}
}

Now, you can use this extended form in your form. Simply change the extends directive with :

class MyGreatForm extends RegistrationForm
{
// …
}

Of course, you have to update your css, for example :

.requiredFormField
{
color: red;
}