0

我尝试将验证码(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);
   }

...这不在这堂课http://prog-school.ru/forum/go.php?https://github.com/kolanos/kohana-captcha/blob/master/classes/captcha.php

问题:

  1. 在变量 $html 中,当您调用此方法时(默认为 config)为 true。因此返回和底层代码不应该被执行,但调试器说相反......它是如何工作的?

  2. 稍后在变量 $function 中通过连接“image”和 $thos->image_type(如上所示 =“png”)传递一个字符串。结果是带有函数名称的行,它给出了 png 格式的图像(“imagepng”)。并且以下行使用了晦涩的语法: $function($this->image); 这些线是做什么的?

我希望有人能帮助我了解它是如何工作的。

4

1 回答 1

0
  1. 配置中的任何地方都没有html设置值。仅当 $html 为 TRUE 即返回才有效image_render(TRUE)image_render(1)如果您调用或image_render('some string')由于语句中===使用了运算符,它将不会执行。在这里if查看以了解更多转换为布尔类型的信息。
  2. 第一行评估函数名称(例如imagepng),第二行调用此函数。有关详细信息,请参阅变量函数。
于 2012-04-10T09:46:10.777 回答