如何找出我的函数错误在哪里(CAKEPHP)

如何找出我的函数错误在哪里(CAKEPHP),cakephp,Cakephp,我很难找出我在函数中哪里出错了,我想知道是否有任何方法可以让我使用NetBean或在执行函数时找出函数在哪里出错 如果您想查看该函数,请参阅其副本: public function archive($id = null) { if ($this->request->is('post')) { $event = $this->Event->read(null, $id); $archive['Archive

我很难找出我在函数中哪里出错了,我想知道是否有任何方法可以让我使用NetBean或在执行函数时找出函数在哪里出错

如果您想查看该函数,请参阅其副本:

             public function archive($id = null) {
    if ($this->request->is('post')) {
        $event =  $this->Event->read(null, $id);
        $archive['Archive'] = $event['Event'];
        $archive['Archive']['archiveID'] = $event['Event']['eventID'];
        unset($archive['Archive']['archiveID']);
        $this->loadModel('Archive');
        $this->Archive->create();
        if ($this->Archive->save($archive)) {
           // $this->Archive->invalidFields();
            $this->redirect(array('action' => 'eventmanage'));
            $this->Session->setFlash(__('The event has been archived'));
          //  $this->Event->delete($id);  
        } else {
            $this->redirect(array('action' => 'eventmanage'));
            $this->Session->setFlash(__('The event could not be archived, Please, contact the administrator.'));
        }
    }
}

so far i have tried using the `$errors = $this->Archive->validationErrors;` function but all i receive back is the word 'array' 
更新

我已将事件另存为存档,但它不会发送消息
$this->Session->setFlash(_uu(“事件已存档”)并且它不会重定向回EventManager,它会创建一个指向/Controller/Action/id的新链接,例如/events/archive/14


谢谢,
validationErrors
属性返回一个数组。您不能在PHP中回显数组对象,因为它是数据的集合,而不是可以“仅仅”输出到屏幕上的东西。还有其他函数可以显示完整的数组,比如,或CakePHP方法或。因此,请尝试以下方法:

$errors = $this->Archive->validationErrors;
if (!empty($errors)) { debug($errors); }
您还可以使用将所有验证错误输出为flash消息中的字符串,例如:

$this->Session->setFlash(__('The event could not be archived, because of the following errors: ' . implode('<br/>', $errors) . '. Please, contact the administrator.'));

validationErrors
属性返回一个数组。您不能在PHP中回显数组对象,因为它是数据的集合,而不是可以“仅仅”输出到屏幕上的东西。还有其他函数可以显示完整的数组,比如,或CakePHP方法或。因此,请尝试以下方法:

$errors = $this->Archive->validationErrors;
if (!empty($errors)) { debug($errors); }
您还可以使用将所有验证错误输出为flash消息中的字符串,例如:

$this->Session->setFlash(__('The event could not be archived, because of the following errors: ' . implode('<br/>', $errors) . '. Please, contact the administrator.'));

我很难理解是否有必要给

$archive['Archive']['archiveID'] = $event['Event']['eventID'];
然后马上就搞定了

unset($archive['Archive']['archiveID']);
如果数据库中的'archiveID'是必需的值,那么我认为MySQL不会接受没有该值的任何数据


您必须检查表的结构。

我很难理解是否需要为表赋值

$archive['Archive']['archiveID'] = $event['Event']['eventID'];
然后马上就搞定了

unset($archive['Archive']['archiveID']);
如果数据库中的'archiveID'是必需的值,那么我认为MySQL不会接受没有该值的任何数据


您必须检查表的结构。

不要使用echo,而是使用pr($errors);公关(错误);返回数组(),它现在显示()这是否意味着我的错误不在存档数据库中?您使用的调试级别是什么<代码>配置::写入('debug',2)app/Config/core.php
中,我有Configure::write('debug',2);不要使用echo,不要使用pr($errors);公关(错误);返回数组(),它现在显示()这是否意味着我的错误不在存档数据库中?您使用的调试级别是什么<代码>配置::写入('debug',2)app/Config/core.php中,我有Configure::write('debug',2);内爆没有返回任何错误,我收到的只是“由于以下错误,事件无法存档:。请与管理员联系。”我更新了else语句,以便您可以看到我的else函数updatedTry
$errors=$this->Archive->invalidFields()
相反,这可能会起作用。这也是一个空数组,我可以假定我的模型因此有效吗?让我们看看内爆没有返回任何错误,我收到的只是“由于以下错误,事件无法存档:。请与管理员联系。”我更新了else语句,以便您可以看到我的else函数updatedTry
$errors=$this->Archive->invalidFields()相反,这可能只是个小把戏。如果其中一个也是空数组,那么我可以假设我的模型因此是有效的吗