Created
February 18, 2011 04:59
-
-
Save 77web/833270 to your computer and use it in GitHub Desktop.
sfFormで簡単に確認画面を作るためのwidget試作品。
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 | |
class someActions extends sfActions | |
{ | |
public function executeConfirm(sfWebRequest $request) | |
{ | |
$this->form->bind($request->getParameter($this->form->getName())); | |
if($this->form->isValid()) | |
{ | |
$this->getUser()->setAttribute($this->form->getName(), $this->form->getValues()); | |
$this->form->configureConfirm(); | |
return sfView::SUCCESS; | |
} | |
$this->setTemplate('new'); | |
} | |
} |
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 | |
class myWidgetFormConfirm extends sfWidgetForm | |
{ | |
protected $choices = array(); | |
protected $type; | |
public function __construct($options = array(), $attributes = array()) | |
{ | |
$this->addRequiredOption('original_widget'); | |
parent::__construct($options, $attributes); | |
} | |
protected function configure($options = array(), $attributes = array()) | |
{ | |
parent::configure($options, $attributes); | |
$this->type = "string"; | |
$original_widget = $this->getOption('original_widget'); | |
if(method_exists($original_widget, "getChoices")) | |
{ | |
$this->choices = $original_widget->getChoices(); | |
$this->type = "choice"; | |
} | |
elseif(get_class($original_widget)=="sfWidgetFormDate" || get_class($original_widget)=="opWidgetFormDate") | |
{ | |
$this->type = "date"; | |
} | |
elseif(get_class($original_widget)=="sfWidgetFormTime") | |
{ | |
$this->type = "time"; | |
} | |
elseif(get_class($original_widget)=="sfWidgetFormTextarea") | |
{ | |
$this->type = "textarea"; | |
} | |
elseif(get_class($original_widget)=="opWidgetFormRichTextareaOpenPNE") | |
{ | |
$this->type = "tinymce"; | |
} | |
} | |
public function render($name, $value = null, $attributes = array(), $errors = array()) | |
{ | |
if($this->type=="date" && is_array($value)) | |
{ | |
//FIXME...date_format?? | |
return implode("/", $value); | |
} | |
if($this->type=="time" && is_array($value)) | |
{ | |
return sprintf('%02d', $value['hour']).':'.sprintf('%02d', $value['minute']); | |
} | |
elseif($this->type=="choice") | |
{ | |
if(is_array($value)) | |
{ | |
$_values = array(); | |
foreach($value as $v) | |
{ | |
if(isset($this->choices[$v])) $_values[] = $this->choices[$v]; | |
} | |
return count($_values)>0?implode(",", $_values):"-"; | |
} | |
else | |
{ | |
return isset($this->choices[$value])?$this->choices[$value]:"-"; | |
} | |
} | |
elseif($this->type=="textarea") | |
{ | |
return nl2br($value); | |
} | |
elseif($this->type=="tinymce") | |
{ | |
return op_url_cmd(op_decoration(nl2br($value))); | |
} | |
return $value; | |
} | |
} |
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 | |
class PluginSomeForm extends BaseSomeForm | |
{ | |
public function configure() | |
{ | |
unset($this['id']); | |
$this->useFields(array('title', 'body')); | |
//usual configure here | |
} | |
public function configureConfirm() | |
{ | |
$this->resetFormFields(); | |
foreach($this as $name => $field) | |
{ | |
$this->setWidget($name, new myWidgetFormConfirm(array('original_widget'=>$this->getWidget($name)))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment