我尝试将验证码(https://github.com/kolanos/kohana-captcha)安装到 Kohana 3.1。模块已安装,但仍然搞砸了,有问题无法找到答案。如果你特别是我无法理解它是如何工作的,这里是代码:
/**
* Returns the img html element or outputs the image to the browser.
*
* @param boolean $html Output as HTML
* @return mixed HTML, string or void
*/
public function image_render($html)
{
// Output html element
if ($html === TRUE)
return '<img src="'.url::site('captcha/'.Captcha::$config['group']).'" width="'.Captcha::$config['width'].'" height="'.Captcha::$config['height'].'" alt="Captcha" class="captcha" />';
// Send the correct HTTP header
Request::instance()->headers['Content-Type'] = 'image/'.$this->image_type;
Request::instance()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
Request::instance()->headers['Pragma'] = 'no-cache';
Request::instance()->headers['Connection'] = 'close';
// Pick the correct output function
$function = 'image'.$this->image_type;
$function($this->image);
// Free up resources
imagedestroy($this->image);
}
问题:
在变量 $html 中,当您调用此方法时(默认为 config)为 true。因此返回和底层代码不应该被执行,但调试器说相反......它是如何工作的?
稍后在变量 $function 中通过连接“image”和 $thos->image_type(如上所示 =“png”)传递一个字符串。结果是带有函数名称的行,它给出了 png 格式的图像(“imagepng”)。并且以下行使用了晦涩的语法: $function($this->image); 这些线是做什么的?
我希望有人能帮助我了解它是如何工作的。