请求似乎已处理但服务器返回错误页面
由于我再次使用 ZendFramework,我开始“扩展”QuickStart 应用程序。 我使用 ZendX jQuery 组件作为视图助手。 我有一个控制器 MonsterController
,除了 indexAction 之外,它还有两个操作:
添加动作
攻击动作
两者都通过 _getParam($param, $default)
获取参数。 addAction 的查询示例为 /monster/add/dragon/health/100/attackDamage/23
。 AttackAction 只需要一个 Id。
实际的问题是,如果我调用其中任何一个,我会收到“应用程序错误”。 除了带有“应用程序错误”的普通页面之外,没有堆栈跟踪或其他任何内容。 这不应该发生。
有趣的是,addAction 实际上执行了一个操作,将所需的怪物添加到数据库中,但attackAction 却什么也不做。
public function attackAction()
{
$id = $this->_getParam("id", null);
$mapper = new Application_Model_MonsterMapper();
$monster = new Application_Model_Monster(array("Id" => $id, "health" => 1));
$mapper->save($monster);
}
public function addAction()
{
$monster = new Application_Model_Monster();
$monster->setName($this->_getParam("name", ""))
->setHealth($this->_getParam("health", 0))
->setAttackDamage($this->_getParam("attackDamage", 0));
$mapper = new Application_Model_MonsterMapper();
$mapper->save($monster);
}
public function save(Application_Model_Monster $model)
{
$data = array(
'name' => $model->getName(),
'health' => $model->getHealth(),
'attackDamage' => $model->getAttackDamage()
);
if (null === ($id = $model->getId())) {
unset($data['id']);
$this->getDbTable()->insert($data);
} else {
$this->getDbTable()->update($data, array('id = ?' => $id));
}
}
since I am using the ZendFramework again, I started to "extend" the QuickStart application.
I use the ZendX jQuery component as View Helper.
I have one Controller MonsterController
this has two actions besides indexAction:
addAction
attackAction
Both take params via _getParam($param, $default)
.
An example query for addAction would be /monster/add/dragon/health/100/attackDamage/23
.
attackAction just takes an Id.
The actual problem is, that if I call any of them I get an "Application Error".
There is no stack trace or anything else than a plain page with "Application Error".
Which should not happen.
The interesting thing is that, addAction actually perfoms an action adding the desired monster to the db, but attackAction just does nothing.
public function attackAction()
{
$id = $this->_getParam("id", null);
$mapper = new Application_Model_MonsterMapper();
$monster = new Application_Model_Monster(array("Id" => $id, "health" => 1));
$mapper->save($monster);
}
public function addAction()
{
$monster = new Application_Model_Monster();
$monster->setName($this->_getParam("name", ""))
->setHealth($this->_getParam("health", 0))
->setAttackDamage($this->_getParam("attackDamage", 0));
$mapper = new Application_Model_MonsterMapper();
$mapper->save($monster);
}
public function save(Application_Model_Monster $model)
{
$data = array(
'name' => $model->getName(),
'health' => $model->getHealth(),
'attackDamage' => $model->getAttackDamage()
);
if (null === ($id = $model->getId())) {
unset($data['id']);
$this->getDbTable()->insert($data);
} else {
$this->getDbTable()->update($data, array('id = ?' => $id));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
转到 application\configs,您会看到有趣的文件:
按“error”在其中按 Ctrl+F,您就会明白下一步该做什么。
Go to application\configs and you'll see there interesting file:
Ctrl+F in it by "error" and you understand what to do next.