Created
October 19, 2012 09:44
-
-
Save 77web/3917202 to your computer and use it in GitHub Desktop.
twitter bootstrapのHTMLを出すためのsfForm用formatter
This file contains 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 | |
/** | |
* sfFormのフォームでtwitter bootstrap用のHTMLを出力するformatterクラス | |
* | |
* @auther Hiromi Hishida<info@77-web.com> | |
*/ | |
class sfWidgetFormSchemaFormatterBootstrap extends sfWidgetFormSchemaFormatter | |
{ | |
protected $rowFormat = '<fieldset class="%status%"><div class="control-group">%label%<div class="controls">%error%%field%%help%%hidden_fields%</div></div></fieldset>'; | |
protected $errorRowFormat = '%errors%'; | |
protected $errorListFormatInARow = '%errors%'; | |
protected $errorRowFormatInARow = '<p class="help-block">%error%</p>'; | |
protected $namedErrorRowFormatInARow = '<p class="help-block">%name%: %error%</p>'; | |
protected $helpFormat = '<p class="help-block">%help%</p>'; | |
protected $decoratorFormat = ''; | |
public function generateLabel($name, $attributes = array()) | |
{ | |
if (isset($attributes['class'])) | |
{ | |
$attributes['class'] .= ' control-label'; | |
} | |
else | |
{ | |
$attributes['class'] = 'control-label'; | |
} | |
return parent::generateLabel($name, $attributes); | |
} | |
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null) | |
{ | |
$row = parent::formatRow($label, $field, $errors, $help, $hiddenFields); | |
if (0 != count($errors)) | |
{ | |
$status = 'control-group error'; | |
} | |
else | |
{ | |
$status = 'control-group'; | |
} | |
return strtr($row, array('%status%' => $status)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment