0

例如,删除链接被点击了两次或来自不同的用户。虽然第一次单击将正确删除我的对象,但第二次单击将在调用 deleteAction 之前失败(因为它已过时)。我怎样才能防止这种情况?

/**
 * action delete
 *
 * @param $upload
 * @dontvalidate $upload
 * @return void
 */
public function deleteAction(Tx_MyExt_Domain_Model_Upload $upload) {
    $this->uploadRepository->remove($upload);
    $this->flashMessageContainer->add('Your Upload was removed.');
    $this->redirect('list');
}

我得到一个例外:

该值必须属于“Tx_MyExt_Domain_Model_Download”类型,但属于“NULL”类型。

在 action 中做某​​事并没有帮助,因为它之前失败了……</p>

4

1 回答 1

0

我假设您有一些流畅的标记,如下所示:

<f:link.action action="delete" arguments="{upload:uploadObjectToDelete}" > ... 

其中说:uploadObjectToDelete当用户单击此链接时,将对象传递给删除操作。当用户单击该链接时,ExtBasePropertyMapper使用与链接一起发送的参数来定位uploadObjectToDelete数据库中的 ,然后将其交给您的控制器和删除操作。

第一次单击后,该删除操作成功地从数据库中删除了对象,并且当您重定向到列表操作时页面会重新加载。但是,这次uploadObjectToDelete对象为空。因此,对于第二次单击,当PropertyMapper尝试查找upload删除操作的参数时,没有要查找的对象。并且由于该upload参数是必需的(即不能是null),因此您会遇到异常。

选项1

Change your list action so that it doesn't show these links when the uploadObjectToDelete object is null. This is probably the best option.

<f:if condition="uploadObjectToDelete">
    <f:link.action action="delete" arguments="{upload:uploadObjectToDelete}" > ... 
</f:if>

Option 2

Change your delete action to accept null arguments:

public function deleteAction(Tx_MyExt_Domain_Model_Upload $upload = null) { ...

But this option doesn't make sense. Why would you allow your user to try and delete an object that is already null?

These are just suggestions.

于 2012-08-31T17:13:06.037 回答