Php Zend framework 2中的控制器调度错误
我从zend控制器返回Json响应 这是我的密码 控制器代码Php Zend framework 2中的控制器调度错误,php,json,zend-framework,zend-framework2,Php,Json,Zend Framework,Zend Framework2,我从zend控制器返回Json响应 这是我的密码 控制器代码 public function get() { $result = //calling other function and getting response in array print("value in controller before calling toJsonModel"); print_r($result); $temp = $this->toJsonModel($result
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
toJsonModel函数
public function toJsonModel($data = array())
{
$data['requestId'] = $this->getHeader('RequestId');
print("Value just before returning to controller");
print_r($data);
return new JsonModel($data);
}
响应
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
第一次和第二次打印显示正确的值。但是在从toJsonModel获取值之后,当我试图显示错误的值并添加一些其他值,如“captureTo”、“terminate”和“children”作为受保护的值时
我不知道为什么它给了我错误的信息
有谁能引导我走上正确的道路,告诉我问题出在哪里
提前谢谢
编辑
我正在添加新的屏幕截图以显示完整的消息
错误:
{“名称”:“未找到电子邮件”,“邮件”:“未找到此电子邮件的帐户”
地址“,”代码“:404,“请求ID:”12“,”原因“:”错误控制器无法调度“,”显示\u异常“:true,“控制器“:”RSMobile\controller\ForgotPassword“,”控制器\u类“:null}”
这是因为您正在将
JsonModel
的对象从方法返回到JsonModel
return new JsonModel($data);
因此,每个对象都有一些属性,可以用来操作数据。参见Zend\View\Model\JsonModel
所以实际上这些值没有错,但是有一种方法可以访问对象的属性
更新
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
附加调度事件
public function onBootstrap($e)
{
// some stuff
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach("dispatch", function($e) {
echo "Dispatch!";
});
// some stuff
}
这是因为您正在将
JsonModel
对象从方法返回到JsonModel
return new JsonModel($data);
因此,每个对象都有一些属性,可以用来操作数据。参见Zend\View\Model\JsonModel
所以实际上这些值没有错,但是有一种方法可以访问对象的属性
更新
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
附加调度事件
public function onBootstrap($e)
{
// some stuff
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach("dispatch", function($e) {
echo "Dispatch!";
});
// some stuff
}
这是因为您正在将
JsonModel
对象从方法返回到JsonModel
return new JsonModel($data);
因此,每个对象都有一些属性,可以用来操作数据。参见Zend\View\Model\JsonModel
所以实际上这些值没有错,但是有一种方法可以访问对象的属性
更新
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
附加调度事件
public function onBootstrap($e)
{
// some stuff
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach("dispatch", function($e) {
echo "Dispatch!";
});
// some stuff
}
这是因为您正在将
JsonModel
对象从方法返回到JsonModel
return new JsonModel($data);
因此,每个对象都有一些属性,可以用来操作数据。参见Zend\View\Model\JsonModel
所以实际上这些值没有错,但是有一种方法可以访问对象的属性
更新
public function get()
{
$result = //calling other function and getting response in array
print("value in controller before calling toJsonModel");
print_r($result);
$temp = $this->toJsonModel($result);
var_dump($temp);
return $temp;
}
附加调度事件
public function onBootstrap($e)
{
// some stuff
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach("dispatch", function($e) {
echo "Dispatch!";
});
// some stuff
}
我终于解决了这个问题 每当出现问题时,我都会从控制器抛出一些错误。我过去常常在找不到电子邮件时抛出404。这导致了这个错误 起初我认为这是一个与JSON模型相关的问题。但是感谢@Bilal帮助我解决了这个问题
当我从控制器抛出404时,默认情况下,它会在末尾附加所有这些数据。但当我抛出404以外的任何错误时,它都是有效的 我终于解决了这个问题 每当出现问题时,我都会从控制器抛出一些错误。我过去常常在找不到电子邮件时抛出404。这导致了这个错误 起初我认为这是一个与JSON模型相关的问题。但是感谢@Bilal帮助我解决了这个问题
当我从控制器抛出404时,默认情况下,它会在末尾附加所有这些数据。但当我抛出404以外的任何错误时,它都是有效的 我终于解决了这个问题 每当出现问题时,我都会从控制器抛出一些错误。我过去常常在找不到电子邮件时抛出404。这导致了这个错误 起初我认为这是一个与JSON模型相关的问题。但是感谢@Bilal帮助我解决了这个问题
当我从控制器抛出404时,默认情况下,它会在末尾附加所有这些数据。但当我抛出404以外的任何错误时,它都是有效的 我终于解决了这个问题 每当出现问题时,我都会从控制器抛出一些错误。我过去常常在找不到电子邮件时抛出404。这导致了这个错误 起初我认为这是一个与JSON模型相关的问题。但是感谢@Bilal帮助我解决了这个问题
当我从控制器抛出404时,默认情况下,它会在末尾附加所有这些数据。但当我抛出404以外的任何错误时,它都是有效的 到底出了什么问题?我收到了“调度错误”。看到屏幕截图。到底出了什么问题?我得到了“调度错误”。看到屏幕截图。到底出了什么问题?我得到了“调度错误”。看到屏幕截图。到底出了什么问题?我得到了“调度错误”。看到截图了。我不想把它添加到这个。顺便说一句,如果我在不同的控制器中使用相同的函数,它可以正常工作,并且不会将此数据添加到对象中。因为我想将其作为API响应返回,而不应该将其添加到此中。@BSThakrar您之所以看到此数据,是因为您正在转储
JsonModel
。删除所有print
、print\r
和var\u dump
语句,您将只得到呈现的json字符串。@BSThrakar显示错误消息的屏幕截图的最后一行丢失。如果你把它包含在问题的文本中,而不是依赖屏幕截图,可能会有所帮助。我不想把它添加到这个问题中。顺便说一句,如果我在不同的控制器中使用相同的函数,它可以正常工作,并且不会将此数据添加到对象中。因为我想将其作为API响应返回,而不应该将其添加到此中。@BSThakrar您之所以看到此数据,是因为您正在转储JsonModel
。删除所有print
、print\u r
和var\u dump
语句,您将只得到呈现的json字符串。@BSThrakar显示错误消息的屏幕截图的最后一行