2
0

Zend_Captcha-Operation.xml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <sect1 id="zend.captcha.operation">
  2. <title>Captcha 操作</title>
  3. <para>
  4. 所有具体的 CAPTCHA 对象实现
  5. <code>Zend_Captcha_Adapter</code>,如下所示:
  6. </para>
  7. <programlisting role="php"><![CDATA[
  8. interface Zend_Captcha_Adapter extends Zend_Validate_Interface
  9. {
  10. public function generate();
  11. public function render(Zend_View $view, $element = null);
  12. public function setName($name);
  13. public function getName();
  14. public function getDecorator();
  15. // Additionally, to satisfy Zend_Validate_Interface:
  16. public function isValid($value);
  17. public function getMessages();
  18. public function getErrors();
  19. }
  20. ]]>
  21. </programlisting>
  22. <para>
  23. 增变器和访问器用于指定和获取 captcha 的标识符。
  24. <code>getDecorator()</code> 可用通过名称或返回一个装饰器对象来指定一个 Zend_Form 装饰器。
  25. 然而用法的关键之处是 <code>generate()</code> 和 <code>render()</code>。
  26. <code>generate()</code> 用于生成 captcha 令牌。这个过程一般存储令牌到会话,所以你
  27. 可以根据后来的请求来比较。
  28. <code>render()</code> 用来解析表示 captcha 的信息 - 可以是图像、figlet 或逻辑问题等。
  29. </para>
  30. <para>
  31. 一般的用例如下:
  32. </para>
  33. <programlisting role="php"><![CDATA[
  34. // Originating request:
  35. $captcha = new Zend_Captcha_Figlet(array(
  36. 'name' => 'foo',
  37. 'wordLen' => 6,
  38. 'timeout' => 300,
  39. ));
  40. $id = $captcha->generate();
  41. echo $captcha->render();
  42. // On subsequent request:
  43. // Assume captcha setup as before, and $value is the submitted value:
  44. if ($captcha->isValid($_POST['foo'], $_POST)) {
  45. // Validated!
  46. }
  47. ]]>
  48. </programlisting>
  49. </sect1>
  50. <!--
  51. vim:se ts=4 sw=4 et:
  52. -->