Yii-验证码不自动刷新

Yii中render和renderPartial的区别就能解释为什么不刷新的原因

在进行页面输出渲染的时候区别:

1.render 输出父模板的内容,将渲染的内容,嵌入父模板。|
2.renderPartial 则不输出父模板的内容。只对本次渲染的局部内容,进行输出。

同时还有个重要的区别:

render 函数内部默认执行processOutput($output)函数, 会将把组件,比如 CTreeView 里面注册到 CClientScript 里面的
需要的脚本进行渲染输出。

而renderPartial() 默认不自动渲染输出客户端脚本,需要进行参数的指定,才会输出:
renderPartial($view,$data=null,$return=false,$processOutput=false)
指定processOutput 为 true 即可。

比如要局部输出 CTreeView ,用renderPartial 进行渲染,如果按照默认processOutput=false 则输出内容,不含有客户端脚本
输出内容则为 正常的 ul 列表。没有树形的折叠效果。 主动设定 processOutput=true 后,CTreeView 所需的,所有客户端脚本就会被正常输出在列表的前面。

下面介绍下要用到的几个相关的函数:

render,renderPartial 不再介绍
processOutput()

<?php
publicfunction render($view,$data=null,$return=false)
{
  if($this->beforeRender($view))
  {
    $output=$this->renderPartial($view,$data,true);
    if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
      $output=$this->renderFile($layoutFile,array(‘content‘=>$output),true);
    $this->afterRender($view,$output);
    $output=$this->processOutput($output);
    if($return)
      return $output;
    else
      echo $output;
  }
}
publicfunction renderPartial($view,$data=null,$return=false,$processOutput=false)
{
  if(($viewFile=$this->getViewFile($view))!==false)
  {
    $output=$this->renderFile($viewFile,$data,true);
    if($processOutput)
      $output=$this->processOutput($output);
    if($return)
      return $output;
    else
      echo $output;
  }
  else
    thrownewCException(Yii::t(‘yii‘,‘{controller} cannot find the requested view "{view}".‘,
      array(‘{controller}‘=>get_class($this),‘{view}‘=>$view)));
}
publicfunction processOutput($output)
{
  Yii::app()->getClientScript()->render($output);
  // if using page caching, we should delay dynamic output replacement
  if($this->_dynamicOutput!==null&& $this->isCachingStackEmpty())
  {
    $output=$this->processDynamicOutput($output);
    $this->_dynamicOutput=null;
  }
  if($this->_pageStates===null)
    $this->_pageStates=$this->loadPageStates();
  if(!empty($this->_pageStates))
    $this->savePageStates($this->_pageStates,$output);
  return $output;
}

以上在实际操作中还是比较有用的,比如你不想用大组建,可以直接将变量输到模板,也可以将多个变量组成数组输到模版里面去.

后台登陆调用验证码,点击验证码不刷新,没有反应(所有验证码配置,参数都是正确的)。找错的时候发现可以刷新验证码的页面比不可以刷新验证码的页面多了一段js代码,用来处理点击验证码刷新的事件。

为什么会少了一段代码?原来就是因为控制器分别调用了renderPartial和render. 下面就说说它们的区别:

在进行页面输出渲染的时候。

render 输出父模板的内容,将渲染的内容,嵌入父模板。
renderPartial 则不输出父模板的内容。只对本次渲染的局部内容,进行输出。
同时还有个重要的区别:

render 函数内部默认执行processOutput($output)函数, 会将把组件,比如 CTreeView
里面注册到CClientScript 里面的需要的脚本进行渲染输出。

而renderPartial() 默认不自动渲染输出客户端脚本,需要进行参数的指定,才会输出:
renderPartial($view,$data=null,$return=false,$processOutput=false)
指定processOutput 为 true 即可。

就像我们遇到的问题,用renderPartial时,页面没有输出验证码刷新的那段js。所以就没有反应。

时间: 2024-08-01 16:18:37

Yii-验证码不自动刷新的相关文章

图片验证码及自动刷新

<script> function imgCode() { $("#imgCode").on("click", function() { $(this).attr("src", '/user/verify?t=' + Math.random()); }); }; /* 当后台返回验证码错误时,绑定trigger("click")事件即可 */ </script>

关于 yii 验证码显示, 但点击不能刷新的处理

先说说 render 与 renderPartial, 各位看官, 先别走, 我没跑题, 这个问题如果需要解决, 关键就在 render 与 renderPartial 的区别. renderPartial() 方法 public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false) $view string name of the vie

yii验证码Captcha使用以及为什么验证码不刷新问题

Web开发的过程中, 经常会用到验证码, 以防止机器人不断的提交数据, 造成网站的瘫痪. Yii里提供了一个验证码的插件, 就是Captcha. 第一步: 在项目中使用Captcha需要以下一些设置:在Controller里添加方法 actions public function actions () { return array ( 'captcha' => array ( 'class' => 'CCaptchaAction' , 'minLength' => 1 , 'maxLen

ExtJs4.2 登陆界面(点击验证码自动刷新,label实现click事件)

ExtJs4.2 登陆界面(点击验证码自动刷新,label实现click事件) 转载请注明:http://blog.csdn.net/qiuzhping/article/details/42596339 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <%@ page langu

页面实现验证码功能,点击“注册”按钮后,无论是否完成注册,验证码都能够自动刷新

要求页面实现验证码功能,点击"注册"按钮后,无论是否完成注册,验证码都能够自动刷新 <script> function validteCode() { var codes = new Array(4);       // var colors = new Array("Red","Green","Gray","Blue","Maroon","Aqua",&

yii 验证码那点事儿

今天要使用yii验证码, 不过, 这个验证码是整站通用的, 也就是说, 有个表单的提交是使用ajax方式来提交, 整站, 不管在哪个地方, 都能点出来此窗口, 来提交信息 关于yii验证码, framework/web/widgets/captcha/CCaptcha.php里, 它源码里有这么一部分 >---protected function renderImage() >---{ >--->---if(!isset($this->imageOptions['id']))

yii 验证码 CCaptcha的总结(转)

今天用到yii的验证码 ccaptcha,经过在网上搜寻 找到以下例子: 1.在controller中加入代码 (1)启用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php public function actions()     {         return array(             // 启用验证码组件             'captcha'=>array(                 'class'=>'CCaptchaA

自己动手打造工具系列之自动刷新简历

0×00 背景 话说搞安全的大佬们都非常忙,自己在一步一步成长中无暇顾及其他琐碎的事情,比如让猎头注意到各位大佬.如何让猎头和大厂注意到自己呢?第一.提高自己在整个行业的曝光度:第二.定时刷新自己的简历:还有第三,第四等等,各位发挥脑洞.针对第一点,很多大佬各有自己的办法,但是针对第二点其实我们有全自动化的解决方案,可以为自己相对地节约点时间.小弟今天就带来自己动手打造工具系列之自动刷新简历.本文主要是针对喜欢写工具的童鞋提供一些思路,并一步一步地分析思路和方法,起一个抛砖引玉的作用吧. 0×0

【webpack】-- 自动刷新

前端需要频繁的修改js和样式,且需要根据浏览器的页面效果不断的做调整:而且往往我们的开发目录和本地发布目录不是同一个,修改之后需要发布一下:另外一点就是并不是所有的效果都可以直接双击页面就能看到,我们常常需要在本地用nginx建一个站点来观察(自己电脑上ok了才放到测试环境去).所以如果要用手工刷新浏览器和手动(或点击)发布,还要启动站点,确实是个不小的体力活.而这三点webpack可以帮我们做到. webpack-dev-server webpack是通过webpack-dev-server(

推荐开发工具系列之--PyF5(自动刷新)

昨天介绍的自动刷新的软件 推荐开发工具系列之--LinrF5(自动刷新)已经是很靠谱了:今天再介绍一款软件,同样靠谱:萝卜白菜各有所爱,看喜欢那种就用那种: 首先下载软件:http://pan.baidu.com/s/1bnttBTt 解压后双击f5.exe即可使用:绿色不用安装:然后复制项目的路径:按下面的截图输入后点击项目: 接着改文件看看效果: 支持Firefox,IE,各种手机浏览器哦,一个F5,所有客户端环境都能搞定,不需要像livereload一样装插件,F5自身就能支持带有服务器技