Archive for the Category symfony

 
 

[Symfony] Custom theme for propel:generate-module

Propel generators are very useful tool, they automate creating of most common CRUD modules. However default theme have serial issues. Mostly, html forms are based on tables and list is not a sfPropelPager.

But there is an easy way to make your own theme based on symfony default. You can find it into sf_pear_dir/data/generator/sfPropelModule/default and add/modify whatever you want. To use it in your app just putt it into sf_project_dir/data/geneator/sfPropelModule directory.

Then using symfony console script use “theme” argument:

empathon@aden ~/workspace/example $ symfony propel:generate-module backend author Author --with-show --theme=clean

I have create my own custom theme with forms on divs, pager, flash messege on delete and create/edit. You can download it here.

Udpate: Few errors fixed.

[Symfony] Getting array of errors from sfForm

That was tricky. I hope it will help somebody.

<?php
class SomeForm extends sfForm
{
	//..
 
	/**
	 * Return array of current errors
	 *
	 * @return array
	 */
	public function getErrorsArray()
	{
		$errors = $embedded_forms_name = array();
		foreach($this->getEmbeddedForms() as $embedded_form){
			$embedded_forms_name[] = $embedded_form->getName();
		}
		foreach($this as $field){
			if($field->hasError())
			{
				if(in_array($field->getName(), $embedded_forms_name)){
					foreach($field as $field_embedded){
						if($field_embedded->hasError()) $errors[$field->getName().'_'.$field_embedded->getName()] = $field_embedded->getError()->__toString();
					}
				} else {
					$errors[$field->getName()] = $field->getError()->__toString();
				}
			}
		}
		return $errors;
	}
}

For embedded forms it return embedded form name plus field name as a key.
You got an idea ;-) It should be standard feature IMHO.

Update:
Of course there is a easier way if you don’t have embedded forms:

//...
foreach ($this as $field) {
	$field->hasError() ? $errors[$field->getName()] = $field->getError()__toString() : null;
}

or

//...
foreach ($this->getErrorSchema()->getErrors() as $name => $error) {
	$errors[$name] = $error->getMessageFormat();
}