2013-11-28 49 views
0

我試圖保存一個Array $銷售。

在這裏,數據到該陣列:

sales 
    0 
     Product 
      id146 
      category 
      descriptiondrei 
      created2013-11-20 14:10:12 
      modified2013-11-20 14:10:12 
      shop_id27 
      category_id1 
      image(null) 
     Shop 
      id27 
      user_id23 
      titlebarby 
      descriptionkleines 
      created2013-10-29 12:51:32 
      modified2013-10-29 12:51:32 
     Category 
      id1 
      imageHaushalt 

在控制器看起來像這樣的方法:

公共函數save_notepad(){

$sales = array(); 

    if($this -> Session -> valid() && $this -> Session -> check('notepad')) { 
     $notepad = $this -> Session -> read('notepad'); 
     $this->loadModel('Product'); 
     $condition = array('Product.id' => $notepad); 
     $sales = $this -> Product-> find('all', array('conditions' => $condition)); 
     } 
    $this -> set('sales', $sales); 

    if ($this->request->is('post')) { 
     $this->Sale->create(); 
     if ($this->Sale->saveall($sales)); 
      $this->Session->setFlash(__('The sale has been saved')); 
      return $this->redirect(array('action' => 'index')); 
     } 
    } 

存在的問題是,當我保存在數據庫中,它只保存了id和創建的日期。

的模式是這樣的: 類銷售擴展AppModel {

public $belongsTo = array(
    'Product' => array(
     'className' => 'Product', 
     'foreignKey' => 'product_id', 
     'conditions' => array('Product.id' => 'Sale.product_id'), 
     'fields' => '', 
     'order' => '' 
    ), 
    'Shop' => array(
     'className' => 'Shop', 
     'foreignKey' => 'shop_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
)); 

}

什麼我需要爲減排做也是「PRODUCT_ID」和「shop_id」,這已經在Array $銷售?

感謝您的幫助!

回答

0

將數組序列化爲xml或json並保存爲數據庫中的單個字符串blob。

0

我已經找到了解決方案:

PHP回聲$這 - >形>輸入( 'PRODUCT-ID',陣列( '類型'> '文本', '值'=> $銷售[」產品 '] [' ID']));

它需要'type'bevor'value'。