cakephp控制器是否可以返回一个Image,基本上需要这个才能生成验证码图像.我尝试从/webroot/files/captcha_gen.php执行此操作并使用.. $ _SESSION ["rand_code"]将代码保存在会话中,但由于某种原因,控制器不会在会话变量列表中显示它.
是的,当然是
你需要设置正确的标题(使用cake2的响应类) http://book.cakephp.org/2.0/en/controllers/request-response.html#cakeresponse
然后你可以打印出图像,它只是浏览器的正常图像:
$this->autoRender = false;
$this->response->type('jpg');
$this->response->body($imageContent);
Run Code Online (Sandbox Code Playgroud)