想要将单个记录插入单个控制器文件的两个表中

时间:2016-05-17 07:46:42

标签: cakephp model-view-controller model controller

listing控制器中,我有一个名为admin_edit的函数,用listing更新cache_popularcitieslisting id列中的记录。

在此功能中,我还要更新listing_assetcache_popularcitieslisting id,该列未更新和更改; listing_asset是一个不同的模型和控制器文件。

admin_edit

class ListingsController extends AppController
{
    function admin_edit($id = null)
   {    
        if($this->data)
        {
            //listing table cache_popularcities column only changed and updated 
            $this->data['Listing']['cache_popularcities'] = 
            '-'.$this->data['Listing']['popularcities'].'-'; 

            //listing_asset table cache_popularcities column can't be changed and updated
            $this->Listing->ListingAsset->data['ListingAsset']['cache_popularcities'] 
                 = '-'.$this->data['Listing']['popularcities'].'-'; 

            if($this->save($this->data,true))
            {
               $this->ListingAsset->save($this->data,true);
            }
        }      
    }
}

1 个答案:

答案 0 :(得分:0)

要访问您需要使用的控制器方法内的数据:

$this->request->data

虽然内部模型方法使用:

$this->data