【问题标题】:CHttpException when trying to submit a form with a captcha尝试使用验证码提交表单时出现 CHttpException
【发布时间】:2015-01-06 13:56:30
【问题描述】:

我是 yii 框架的新手,我正在尝试在我的本地 zwamp 环境中执行一个 php 应用程序。该应用程序在生产环境中正常工作。

我收到的错误是在填写表格并尝试提交之后。验证码未验证,我在日志中收到以下错误:

2014/11/10 10:23:17 [error] [exception.CHttpException.404] exception 'CHttpException' with message 'The system cannot find the action « undefined » that is requested.' in D:\Users\....\web\CController.php:483
Stack trace:
#0 D:\Users\...\web\CController.php(270): CController->missingAction('undefined')
#1 D:\Users\...\web\CWebApplication.php(282): CController->run('undefined')
#2 D:\Users\...\web\CWebApplication.php(141): CWebApplication->runController('site/undefined')
#3 D:\Users\...\base\CApplication.php(180): CWebApplication->processRequest()
#4 D:\Users\....\index.php(23): CApplication->run()
#5 {main}
REQUEST_URI=/appname/site/undefined
HTTP_REFERER=http://localhost:92/appname/site/form

如何解决此问题或确定是哪个操作导致了问题?

**编辑:问题似乎来自这里:验证码与显示的图像不匹配.. **

/**
 * Gets the verification code.
 * @param boolean $regenerate whether the verification code should be regenerated.
 * @return string the verification code.
 */
public function getVerifyCode($regenerate=false)
{
    if($this->fixedVerifyCode !== null)
        return $this->fixedVerifyCode;

    $session = Yii::app()->session;
    $session->open();
    $name = $this->getSessionKey();
    if($session[$name] === null || $regenerate)
    {
        $session[$name] = $this->generateVerifyCode();
        $session[$name . 'count'] = 1;
    }


    $message = $session[$name];
    echo "<script type='text/javascript'>alert('$message');</script>";


    return $session[$name];
}

可能是什么问题?

【问题讨论】:

  • 你使用CCaptchaAction吗?
  • 是的,我正在使用 CCaptchaAction
  • 请显示您创建 CCaptcha 小部件和验证规则的代码。
  • 添加了相关代码。 $session[$name] 值与显示的图像不匹配
  • Action id 未解析。在此处发布您的控制器/视图/配置代码以更好地了解您的问题

标签: php yii captcha


【解决方案1】:

Ayrad,错误信息很含糊,比如“...action « undefined ».....”,通常 Yii 404 错误指定了它的名称(例如,“...Unable to resolve the请求“ABC XYZ ....”)。

这些错误取决于很多事情,比如是否启用了引擎重写,您的 .htacess 怎么样。至少,您的“URLManager”在您的配置中看起来如何。

所以,我的回答来自我之前遇到的问题的经验。它们是我的 CSS 文件中的一些损坏的链接,所以我得到了这样的错误,

[error] [exception.CHttpException.404] exception 'CHttpException' with message 'The system is unable to find the requested action "undefined".' in C:\wamp\yii\framework\web\CController.php:484
Stack trace:
#0 C:\wamp\yii\framework\web\CController.php(271): CController->missingAction('undefined')
#1 C:\wamp\yii\framework\web\CWebApplication.php(283): CController->run('undefined')
#2 C:\wamp\yii\framework\web\CWebApplication.php(142): CWebApplication->runController('site/undefined')
#3 C:\wamp\yii\framework\base\CApplication.php(162): CWebApplication->processRequest()
#4 C:\wamp\www\index.php(27): CApplication->run()
#5 {main}
REQUEST_URI=/site/undefined
HTTP_REFERER=http://localhost/site/index

我检查了我的主布局,发现这个错误的 javascript 函数导致了这个错误:

$(".shortcuts").each(function(){
        var cacheImage = document.createElement('img');
        cacheImage.src = $(this).attr('rel');
        cache.push(cacheImage);
        });

假设在引导导航栏上预加载快捷方式图像。这样就解决了问题。希望这可以帮助。如果没有,请尝试发布更多详细信息。

【讨论】:

    【解决方案2】:

    错误日志清楚地显示了这是关于什么的,

    REQUEST_URI=/appname/site/undefined
    

    这表明你以某种方式生成了一个这样的 url,当它试图使用它来解决时,它失败了(我认为这是你的表单 url)

    您必须分享才能查看制作此表单的内容,否则我们无法为您提供帮助

    【讨论】:

    • 这不是答案,最好将其添加为评论。
    【解决方案3】:

    如果此代码在生产环境中正常工作。那么问题可能是由于数据库或 main.php 不匹配造成的。我认为,此错误是由于未正确获取站点操作。检查一下,请求的 URL 是正确的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2018-02-01
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多