Kohana 3.1模块验证码。这个怎么运作?

时间:2012-04-08 18:15:25

标签: php kohana

我尝试将Captcha(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-&gt; image_type(如上所示=“png”)传递一个字符串。事实证明,该行具有以png格式(“imagepng”)提供图像的函数名称。以下行使用了晦涩的语法:$ function($ this-&gt; image);这些行做什么?

  3. 我希望有人能帮助我理解它是如何运作的。

1 个答案:

答案 0 :(得分:0)

  1. 配置中的任何位置都没有设置html值。仅当$ html为TRUE即image_render(TRUE)时,返回才有效。如果您因image_render(1)语句中使用image_render('some string')运算符而致电===if,则无法执行此操作。检查here以了解更多转换为布尔类型的信息。
  2. 第一行评估函数名称(例如imagepng),第二行调用此函数。有关详细信息,请参阅variable functions