Yii:相同的路线,但只有GET在确认没有控制器过滤器后才能工作

时间:2013-11-20 01:35:17

标签: yii

我的urlManager规则:(基本上是默认的)

'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',`

我的控制器:

class SiteController extends Controller {
    public function actionSubscribe() {
        echo 'gdg';
        die();
    }
}

我的观点:

<form method="POST" action="<?php echo $this->createUrl('site/subscribe'); ?>" style="display: inline;">
    <input style="margin: 0 18px 0 6px;" type="text" value="e-mail"/>
</form>

当我使用网址http://localhost/site/subscribe直接访问它时,它可以正常工作,但是当我在文本字段中输入内容并按下我的输入按钮发布表单时,它会显示The system is unable to find the requested action "error". 我非常肯定它与我的表格有关。到目前为止,我没有使用活动表单的问题但是对于这种表单,我没有模型,我不想使用表单生成器。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

“当我使用网址http:// * / site / subscribe直接访问它时,它可以正常运行”

=&GT;您可以使用GET方法执行subscribe操作。

“但是当我在文本字段中输入内容并按下我的输入按钮发布表单时,系统无法找到所请求的操作”错误“。”

=&GT;您可以使用POST方法执行subscribe操作。

=&GT;有一些错误,我认为Yii尝试使用您的默认配置处理错误:

return array(
    ......
    'components'=>array(
        'errorHandler'=>array(
            'errorAction'=>'site/error',
        ),
    ),
);

但是,Yii无法使用您的error找到SiteController操作,因此会抛出The system is unable to find the requested action "error".您可以添加error操作以查看有关错误的信息,例如:

public function actionError()
{
    if($error=Yii::app()->errorHandler->error){
        $this->render('error', $error);
     }
}

更多信息:上述error变量是一个包含以下字段的数组:

code: the HTTP status code (e.g. 403, 500);
type: the error type (e.g. CHttpException, PHP Error);
message: the error message;
file: the name of the PHP script file where the error occurs;
line: the line number of the code where the error occurs;
trace: the call stack of the error;
source: the context source code where the error occurs.
相关问题