2014-03-28 61 views
0

控制器創建UserController.php蛋糕PHP數據不保存到數據庫表

public function myappointment() { 

     $this->loadmodel('event'); 
     if ($this->request->is('post')) { 
      $this->Event->create(); 

      if ($this->Event->save($this->request->data)) { 
       $this->Session->setFlash(__('Your appointment has been saved.')); 
      } else { 
       $this->Session->setFlash(__('Unable to add your appointment.')); 
      } 
     } 
    } 

型號名稱事件鑑於 event.php

class Event extends UserMgmtAppModel { 


} 

約會表單代碼

<?php 
$this->Form->create('Event'); 

echo $this->Form->input("title" ,array('label' => false)); 

echo $this->Form->input("from", array('label' =>false, 'type' => 'text', 'class' => 'fl tal vat w300p', 'error' => false , 'id' => 'select_date')); 
echo $this->Html->div('datepicker_img w100p fl pl460p pa', $this->Html->image('calendar.png'),array('id' => 'datepicker_img')); ?> 
     <?php echo $this->Html->div('datepicker fl pl460p pa', ' ' ,array('id' => 'datepicker')); 
echo 'End time'; 
echo $this->Form->input("to", array('label' =>false, 'type' => 'text', 'class' => 'fl tal vat w300p', 'error' => false , 'id' => 'select_date1')); 
echo $this->Html->div('datepicker_img1 w100p fl pl460p pa', $this->Html->image('calendar.png'),array('id' => 'datepicker_img1')); ?> 
     <?php echo $this->Html->div('datepicker1 fl pl460p pa', ' ' ,array('id' => 'datepicker1')); 

echo $this->Form->end('Create appointment'); 
+0

u能請告訴我如何插入值到數據庫中。我們需要一個步驟來創建控制器,型號,CTP文件 – vijay

+0

'類的事件擴展UserMgmtAppModel {'你確定嗎? –

+0

是類創建像 – vijay

回答

0

在你的模型中試試這個。

App::uses('UserMgmtAppModel', 'Event.Model'); 

class Event extends UserMgmtAppModel { 

} 

你的控制器動作

public function myappointment() { 

    $this->loadmodel('Event'); 
    if ($this->request->is('post')) { 
     $this->Event->create(); 

     if ($this->Event->save($this->request->data)) { 
      $this->Session->setFlash(__('Your appointment has been saved.')); 
     } else { 
      $this->Session->setFlash(__('Unable to add your appointment.')); 
     } 
    } 
} 
+0

**仍然有錯誤**錯誤:調用成員函數create()在非對象上\t File:E :\瓦帕\ WWW \試驗工作\ cakephp的-2.4.5 \應用\插件\ Usermgmt \控制器\ UsersController.php \t 線:547 – vijay

+0

'$這 - > loadmodel( '事件');'應'$這 - > loadmodel( '事件');'。我已經編輯我的答案,現在檢查 –

+0

它的工作....... – vijay