请求似乎已处理但服务器返回错误页面

发布于 2024-11-09 00:40:22 字数 1626 浏览 3 评论 0原文

由于我再次使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2024-11-16 00:40:22

转到 application\configs,您会看到有趣的文件:

application.ini

按“error”在其中按 Ctrl+F,您就会明白下一步该做什么。

Go to application\configs and you'll see there interesting file:

application.ini

Ctrl+F in it by "error" and you understand what to do next.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文