CakePHP:调用testAction到一个json返回方法会导致缺少视图异常 [英] CakePHP: calling testAction to a json-returning method causes missing view exception

查看:138
本文介绍了CakePHP:调用testAction到一个json返回方法会导致缺少视图异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里缺少什么?这是我的控制器代码:

What am I missing here? Here is my controller code:

public function calculate() {
    $this->set(array(
        "route" => array("A" => 1, "B" => 2),
        "_serialize" => array("route")
    ));

    return;
}

这是我的routes.php文件中的一行:

Here is a line from my routes.php file:

Router::parseExtensions();

这是我的测试代码:

    $result = $this->testAction("/itinerary/calculate.json", array(
        "method" => "POST", 
        "return" => "contents"
    ));

此代码会引起

MissingViewException: View file "C:\xampp\htdocs\fiver\app\View\Itinerary\calculate.ctp" is missing.

我明显缺少这里的东西。请帮忙。对另一个使用JSON的控制器的另一个测试很好。

I am obviously missing something here. Please help. Another test for another controller with JSON works just fine

推荐答案

CakePHP需要将RequestHandler组件显式地添加到控制器以使扩展工作。我已经添加了这一行,它开始工作了

Got it. CakePHP requires the RequestHandler component to be explicitly added to the controller for the extensions to work. I've added this line, it started to work

public $components = array('RequestHandler');

这篇关于CakePHP:调用testAction到一个json返回方法会导致缺少视图异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆