두 가지 옵션이 있습니다 (두 번째가 더 쉽다).
첫 번째 옵션 : 고객님의 sfWidgetFormInputFileEditable
을 만들고 원본을 확장하십시오. 파일 lib/widget/myWidgetFormInputFileEditable.class.php
에서
는 :
class myWidgetFormInputFileEditable extends sfWidgetFormInputFileEditable
{
protected function getFileAsTag($attributes)
{
if ($this->getOption('is_image'))
{
if (false !== $src = $this->getOption('file_src'))
{
// check if the given src is empty of image (like check if it has a .jpg at the end)
if ('/uploads/car/' === $src)
{
$src = '/uploads/car/default_image.jpg';
}
$this->renderTag('img', array_merge(array('src' => $src), $attributes))
}
}
else
{
return $this->getOption('file_src');
}
}
}
그런 다음 당신은 그것을 호출 할 필요가 :
$this->widgetSchema['picture1'] = new myWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/car/'.$this->getObject()->getPicture1(),
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
두 번째 옵션 : 개체가 새로운 선택하면 다음 기본 이미지를 사용합니다.
$file_src = $this->getObject()->getPicture1();
if ($this->getObject()->isNew())
{
$file_src = 'default_image.jpg';
}
$this->widgetSchema['picture1'] = new sfWidgetFormInputFileEditable(array(
'label' => ' ',
'file_src' => '/uploads/car/'.$file_src,
'is_image' => true,
'edit_mode' => true,
'template' => '<div>%file%<br />%input%</div>',
));
출처
2012-07-11 10:41:47
j0k
감사합니다. j0k !! 너는 생명의 은인이야. 두 번째 옵션은 내가하고자하는 것 이상이지만 form.class 파일에 "if"문을 작성할 수 있다는 것을 인식하지 못했습니다. 다시 한 번 감사드립니다! – djcloud23