2016-01-23 70 views
1
Class FramingPartnersController extends CroogoAppController { 

public $components = array('Paginator', 'Session'); 
public $uses = array('FramingPartner'); 

public function index() { 
    $test = 'This is Framing Partners Index'; 
    $this->set(compact('test')); 
    } 

public function profile() { 
    if(!empty($this->request->data)){ 

    if ($this->request->is('post')) { 
     $this->FramingPartner->create(); 
     if ($this->FramingPartner->save($this->request->data)) { 
     $this->Session->setFlash(__d('croogo', 'The profile has been saved'), 'flash', array('class' => 'success')); 
     $this->redirect(array('action' => 'frames')); 
     } else { 
     $this->Session->setFlash(__d('croogo', 'The profile could not be saved. Please, try again.'), 'default', array('class' => 'error')); 
     } 
    } 
    } 
} 

    public function frames() { 
    $test = 'This is Framing Partners frames'; 
    $this->set(compact('test')); 
    } 

}如何發送兩個不同的數據到兩個不同的表中,從cakephp中同一個控制器中的兩個不同的動作?

我有每兩個的輪廓和框架不同的表,並希望將數據從上述動作傳送給各自的表。 簡而言之,來自配置文件的數據應該發送到配置文件表,並且來自幀的數據應該發送到幀表。

+0

Profile和Frame模型和FramingPartner模型之間是否存在關聯? –

回答

1
public function frames(){ 
    if(!empty($this->request->data)){ 
     if ($this->request->is('post')) { 
      $this->loadModel('Frame'); 
      $this->Frame->create(); 
      if ($this->Frame->save($this->request->data)) { 
       $this->Session->setFlash(__d('croogo', 'The profile has been saved'), 'flash', array('class' => 'success')); 
       /* $this->redirect(array('action' => 'frames'));*/ 
      } else { 
       $this->Session->setFlash(__d('croogo', 'The profile could not be saved. Please, try again.'), 'default', array('class' => 'error')); 
       } 
     } 
    } 
} 

以這種方式,我從不同的控制器加載不同的模型,即從FramingPartnersController加載框架模型。

顯式地,我正在加載Frame Model,它將自動加載Frame表。

+0

它在當地正常工作,但在現場我收到錯誤消息,說內部錯誤發生。 – Swamy

相關問題