Created
March 13, 2012 12:25
-
-
Save nexik/2028466 to your computer and use it in GitHub Desktop.
Symfony helpful snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class myComponents | |
| { | |
| protected function refresh($request) | |
| { | |
| $this->getController()->redirect($request->getUri()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // If $form->renderHiddenFields() render empty value for csrf that means something bad happen in Symfony session | |
| // hard refresh (Ctrl+F5) will solve the problem | |
| class myForm 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; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment