[英]symfony pass resource identifier to template from action
my action: 我的动作:
public function executePreview(sfWebRequest $request)
{
$this->setLayout('layout_preview');
$text='';
$text= $request->getGetParameter('text');
$this->img='';
$this->img2=$this->createImage(array('font_size'=>10, 'line_spacing'=>1.5,'font'=>'dejavu', 'angle'=>10,
'preset'=>'BRCA', 'text'=>$text));
}
public function createImage( $params)
{
$x=0;
$y=0;
$interval= $params['font_size']*$params['line_spacing'];
$src_image= imagecreatefromjpeg(sfConfig::get('sf_web_dir').'/images/'.$params['preset'].'.jpg');
$black = imagecolorallocate($src_image, 0, 0, 0);
$lines=explode("\n", $params['text']);
putenv('GDFONTPATH='.join(':',sfConfig::get('app_font_path')));
$fontname=$params['font'].'.ttf';
foreach($lines as $i=>$line):
imagettftext($src_image, $params['font_size'], $params['angle'], $x, $y+$i*$interval, $black, $fontname, $line);
endforeach;
return $src_image;
}
in my template: 在我的模板中:
<?php
imagejpeg($img2);
?>
but when trying to GET
/modulename/preview?preview=something&text=somethingelse
, it gives an error. 但是在尝试
GET
/modulename/preview?preview=something&text=somethingelse
,会出现错误。 viewing the source of the webpage obtained, I see : 查看所获得网页的来源,我看到:
<title>InvalidArgumentException: Unable to escape value "NULL".</title>
Can I not pass resource identifier to the template? 我不能将资源标识符传递给模板吗? What can be a way around that?
有什么办法可以解决? I need this
createImage
function elsewhere also, I'm just trying to follow DRY
我也在其他地方也需要这个
createImage
函数,我只是想遵循DRY
imagejpeg creates the image and returns a boolean, i don't get why you call it in your view, it should stay to your action, actually i wouldn't use view at all in your case. imagejpeg创建图像并返回一个布尔值,我不明白为什么要在视图中调用它,它应该保持您的操作,实际上我不会在您的情况下使用视图。
try something like : 尝试类似的东西:
$this->getResponse()->setHttpHeader('Content-type', 'image/jpeg');
$this->getResponse()->setContent($src_image);
$this->setLayout(false);
or directly setting header with PHP and returning sfView::HEADER_ONLY 或直接使用PHP设置标头并返回sfView :: HEADER_ONLY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.