使用 Flex 数据管理和 PHP 时出现问题

发布于 2024-11-13 22:41:05 字数 344 浏览 1 评论 0原文

我正在使用 Flash Builder 4.5 for PHP 中的薪资管理系统。我正在使用 Flex 数据管理系统。我有一些问题,如下所述:

  1. 当我将项目添加到数据网格但不提交时,我无法删除它。这是可以理解的,因为删除仅当该项目位于数据库中时才有效,并且在将其提交到数据库之前我无法获取该项目的 id(主键)。

当我删除项目时,应该将其从数据网格中删除(这可以通过从数据网格的数据提供程序中删除项目来实现),但问题是当我提交它时 - 它保存到数据库中。我无法找到解决这个问题的方法。

有哪些关于 Flex 4 的好书/教程,重点关注 PHP 和 Flex 企业应用程序开发并通过示例解释应用程序开发?

I am working with a salary managment system in Flash Builder 4.5 for PHP. I am using a Flex data management system. I have a few issues which are addressed below:

  1. When I add an item to data grid and do not commit it, I am not able to delete it. This is understood because delete works only if the item is in the database and I don't get the id (primary key) for the item until I commit it to the database.

When I delete item it should be removed from the data grid (which can be achieved by removing items from the datagrid's data provider), but the issue is when I commit it - it saves to database. I am not able to find any solution to this problem.

What is some good book / tutorial for Flex 4 that focuses on PHP and Flex enterprise application development and explains application development with examples?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

却一份温柔 2024-11-20 22:41:05

这就是我在这种情况下所做的事情。对于我的 dataProvider 中尚未保存的已删除的行(它们的 ID=0 或其他内容),我只需使用以下内容删除它们:

myArrayCollection.removeItemAt(myArrayCollection.getItemIndex(myDataGrid.selectedItem));

这样,任何已删除的行将永远不会到达后端。

Here's what I've done in this situation. For rows in my dataProvider that have not been saved yet (they have ID=0 or something) that are deleted, I just remove them using something like:

myArrayCollection.removeItemAt(myArrayCollection.getItemIndex(myDataGrid.selectedItem));

This way any rows that were deleted will never make it to the back end.

暮年 2024-11-20 22:41:05

我没有使用数据网格(或 ArrayCollection 作为数据提供者),因此虽然 @Jason Towne 的解决方案一般有效,但它不是针对我的具体情况的解决方案。

我通过使用 Flex 中的数据管理 DELETE 方法的 item 而不是 itemID 解决了“无法删除未提交的项目”问题。 Flash Builder 自动生成的 ActionScript 方法和 PHP 代码使用 itemID 作为参数,该参数在将记录保存到数据库之后才适用于数据管理的 DELETE。在 DELETE 方法中使用实际的 item 引用作为参数可以删除已提交和未提交的更改。然后必须修改 PHP 代码。

我使用服务器端输入,因此修改后的 PHP 代码(与 FB 自动生成的 PHP 代码非常相似)如下所示:

/**
 * Deletes the item corresponding to the passed primary key value from 
 * the table. Note: NOT using primary key anymore - use item reference.
 *
 * Add authorization or any logical checks for secure access to your data 
 *
 * @param MessageScheduleItem $item
 * @return void
 */
public function delete_messageScheduleItem($item) {

    $stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE ID = ?");
    $this->throwExceptionOnError();

    mysqli_stmt_bind_param($stmt, 'i', $item->ID);
.
.
... etc.

Flex 代码:

messageScheduleItemService.delete_messageScheduleItem(item);

I'm not using a datagrid (or ArrayCollection as dataProvider) so although @Jason Towne 's solution works in general, it wasn't a solution for my specific case.

I resolved the 'not being able to delete uncommitted items' problem by using item rather than itemID for the data managed DELETE method in Flex. Flash Builder's auto generated ActionScript method and PHP code uses itemID as parameter which doesn't work on data managed DELETE till AFTER a record is saved to database. Using the actual item reference as param in DELETE method works to delete committed AND uncommitted changes. PHP code will then have to be modified.

I use server side typing, so the modified PHP code (which closely resembles FB auto generated PHP code) looks like:

/**
 * Deletes the item corresponding to the passed primary key value from 
 * the table. Note: NOT using primary key anymore - use item reference.
 *
 * Add authorization or any logical checks for secure access to your data 
 *
 * @param MessageScheduleItem $item
 * @return void
 */
public function delete_messageScheduleItem($item) {

    $stmt = mysqli_prepare($this->connection, "DELETE FROM $this->tablename WHERE ID = ?");
    $this->throwExceptionOnError();

    mysqli_stmt_bind_param($stmt, 'i', $item->ID);
.
.
... etc.

The Flex code then:

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