Archive for the Category php

 
 

[Symfony] Clean Doctrine generator for Symfony 1.3beta1

Features:

  • clean forms – based on div’s, no tables
  • sfDoctrinePager on list action
  • index action renamed to list
  • “Actions” column into list table with “Edit” and “Delete” links
  • h1 headers replaced with h2 tag
  • “New” link moved to top and renamed to “Add new”

Have a nice usage! :-)

Download: clean_doctrine_generator.tar

Importand: You need a pager template placed into “global/pager” or change it to other location as you prefer.

[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();
}

phpBB 3.0.1 restorerror

Co by nie mówić o phpBB jest najpopularniejszym skryptem forum. W wersji 3.x dorobił się wielu udogodnień, ślicznego panelu ale ja nie o tym. Jak myślicie czy w ramach zmiany ostatniej cyferki w szale wersjonowania oprogramowania można zapomnieć o kompatybilności wstecznej?
Do czego pieje? phpBB posiada bardzo sprytny mechanizm Restore i oczywiście w komplecie z nim Backup. Cóż on robi? Powinien zrzucić całą naszą bazę danych do archiwum w odpowiednim katalogu żeby potem za pomocą funkcji “Restore” bezproblemowo ją przywrócić. Cud, miód i orzeszki. No niestety nie.
Okazuje się, że Backup z wersji 3.0.0 nie działa na wersji 3.0.1. Wysypuje kompletnie forum, uniemożliwiając zalogowanie się do panelu w celu przywrócenia działającej wersji. Z perspektywy zwykłego użytkownika musimy najpierw zainstalować phpBB 3.0.0 zrobić “restore” i dopiero potem upgrade do 3.0.1. Tak chyba być nie powinno prawda?