0

我有一个类“列表”,其中包含以下字段:

static $db = array(
            ...
            'Left' => 'Varchar',
            'Top' => 'Varchar'
            ...
    );

我正在抓取这些以显示在地图上:

function getListings(){
        $sqlQuery = new SQLQuery();
        $sqlQuery->setFrom('ListingCategory_Listings');
        $sqlQuery->selectField('STLC.Title AS cTitle, STLL.Title AS lTitle, Listing_Live.ID AS lID, ListingCategory.ID as cID, Phone, Email, Website, Filename, Top, Listing_Live.Left, STLC.ID AS catID');
        $sqlQuery->addLeftJoin('Listing_Live', '"ListingCategory_Listings"."ListingID" = "Listing_Live"."ID"');
        $sqlQuery->addLeftJoin('SiteTree_Live', '"Listing_Live"."ID" = "STLL"."ID"', 'STLL');
        $sqlQuery->addLeftJoin('ListingCategory', '"ListingCategory_Listings"."ListingCategoryID" = "ListingCategory"."ID"');
        $sqlQuery->addLeftJoin('SiteTree_Live', '"ListingCategory"."ID" = "STLC"."ID"', 'STLC');
        $sqlQuery->addLeftJoin('File', '"ListingCategory"."IconID" = "File"."ID"');
        $sqlQuery->addWhere('"Listing_Live"."ID" IS NOT NULL');
        $sqlQuery->setOrderBy('ListingCategory.ID', 'ASC');
        $result = $sqlQuery->execute();
        $dataObject = new ArrayList();
        foreach($result as $row) { 
            $dataObject->push(new ArrayData($row)); 
        }
        return $dataObject;
    }

我有一个函数来更新对象的左值和上值(通过在前端拖放对象的实例通过 AJAX 触发):

function updatePoi(){
        $left = $_POST['left'];
        $top = $_POST['top'];
        $id = $_POST['ID'];
        if ($poi = DataObject::get_one('Listing', '"Listing"."ID" = '.$id)){
            $poi->Left = $left;
            $poi->Top = $top;
            $poi->write(); 
            return 'success';
        }else{
            return 'error';
        }
    }

这些肯定会更新,因为在页面刷新时,对象反映了更新的 Top 和 Left 值,但是我在 CMS 中显示了这些字段,但它们在这里显示为空白。此外,当我在 CMS 中保存对象时,Left 和 Top 值被清除,我必须在前端重新定位它们。

有谁明白为什么会这样?

更新:似乎 write() 只更新 Listing_Live 表,而不是 Listing 表,如果不使用原始 SQL 执行此操作,我怎样才能让它同时更新?

4

2 回答 2

1

我建议使用

$poi->Top = $top;
$poi->write(); 
$poi->publish("Live", "Stage");
于 2012-10-17T06:25:31.730 回答
0

作为快速修复,我已将更新功能更改为:

function updatePoi(){
        $left = $_POST['left'];
        $top = $_POST['top'];
        $id = $_POST['ID'];
        DB::query('UPDATE "Listing" SET "Left"='.$left.', "Top"='.$top.' WHERE "ID"='.$id);
        DB::query('UPDATE "Listing_Live" SET "Left"='.$left.', "Top"='.$top.' WHERE "ID"='.$id);
        return 'success';
    }

我很高兴听到这样做的更整洁的方式。

于 2012-10-16T21:27:16.420 回答