我有一个名为 View1.ctp 的视图。在这个视图中,我正在调用一个名为“Captcha”的控制器函数,它的视图是 captcha.ctp。我在视图 captcha.ctp 中有一个名为 $text 的变量。我想访问这个 $text我 view1.ctp 中的变量。我该怎么办?(注:Cakephp 版本-2.3)
View1.ctp
<h1>Add Comment</h1>
<?php
$post_id= $posts['Post']['id'];
echo $this->Form->create('Comment',array('action' => 'comment','url' => array($post_id,$flag)));
echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('text', array('rows' => '3'));
echo "Enter Captcha Code: ";
echo $this->Html->image(
array('controller' => 'posts', 'action' => 'captcha'));
echo $this->Form->input('code');
echo $this->Form->end('Add comment');
?>
captcha.ctp:
<?php
$this->Session->read();
$text = rand(10000,99996);
$_SESSION["vercode"] = $text;
$height = 25;
$width = 65;
$image_p = imagecreate($width, $height);
$black = imagecolorallocate($image_p, 0, 0, 0);
$white = imagecolorallocate($image_p, 255, 255, 255);
$font_size = 14;
imagestring($image_p, $font_size, 5, 5, $text, $white);
imagejpeg($image_p, null, 80);
?>