2012-04-28 143 views
1

嗨,我下載了opencart版本1.5.2.1 ...現在我正在開發一個API使用opencart flow.i開發了使用tpl,控制器,語言文件。 我寫的模型also.what確切的概念是當我輸入表單數據,應該加載到數據庫中...但它顯示一個錯誤,說在model.how中的未定義的索引獲取控制器中的表單數據,以及如何通過數據到模型... 請幫助我。使用MVC插入PHP表單數據到mysql數據庫時出現錯誤

這是我的控制文件:

  <?php 
    class ControllerSaleAd extends Controller { 
private $error = array(); 

public function index() { 

    $this->load->language('sale/ad'); 


    $this->document->setTitle($this->language->get('heading_title')); 

    $this->load->model('sale/ad'); 
$this->data['heading_title']=$this->language->get('heading_title'); 
$this->data['entry_customer_name'] = $this->language->get('entry_customer_name'); 
$this->data['column_name']=$this->language->get('column_name'); 
$this->data['column_place'] = $this->language->get('column_place'); 
$this->data['column_date'] = $this->language->get('column_date'); 

$this->data['column_units'] = $this->language->get('column_units'); 
$this->data['column_price'] = $this->language->get('column_price'); 
$this->data['button_insert'] = $this->language->get('button_insert'); 


$this->data['breadcrumbs'] = array(); 

$this->data['breadcrumbs'][] = array(
      'text'  => $this->language->get('text_home'), 
      'href'  => $this->url->link('sale/ad', 'token=' . $this->session->data['token'], 'SSL'), 
      'separator' => false 
); 

$url=''; 
$this->data['action'] = $this->url->link('sale/ad', 'token=' . $this->session->data['token'] . $url, 'SSL'); 

$this->template='sale/ad.tpl'; 
$this->children = array(
      'common/header', 
      'common/footer' 
); 

$this->response->setOutput($this->render()); 

$this->insert(); 
/*$this->load->model('sale/ad'); 

$this->data['orders']= array(); 
$data=array(
'customer' => $customer, 
'adtype' => $adtype, 
'adplace' => $adplace, 
'date'  => $date, 
'units'  => $units, 
'price'  => $price, 
); 

$results = $this->model_sale_ad->insert($data); 

$this->redirect($this->url->link('sale/ad', 'token=' . $this->session->data['token'] . $url, 'SSL'));*/ 
} 

public function insert() { 
    echo("inserting data"); 

    $this->load->model('sale/ad'); 

    if (($this->request->server['REQUEST_METHOD'] == 'POST')) { 

     echo("hello"); 
     echo($this->request->post); 
     echo($this->model_sale_ad->insert); 
     $this->model_sale_ad->insert($this->request->post); 


     echo("in if method"); 


     /*$url = ''; 

     if (isset($this->request->get['customer'])) { 
      $url .= '&customer=' . $this->request->get['customer']; 
     } 

     if (isset($this->request->get['adtype'])) { 
      $url .= '&adtype=' . $this->request->get['adtype']; 
     } 

     if (isset($this->request->get['adplace'])) { 
      $url .= '&adplace=' . $this->request->get['adplace']; 
     } 

     if (isset($this->request->get['date'])) { 
      $url .= '&date=' . $this->request->get['date']; 
     } 

     if (isset($this->request->get['units'])) { 
      $url .= '&units=' . $this->request->get['units']; 
     } 

     if (isset($this->request->get['price'])) { 
      $url .= '&price=' . $this->request->get['price']; 
     } 


      $customer= $this->request->get[$entry_customer_name]; 
      echo($customer); 
     $data=array(
     'customer' => $customer, 
     'adtype' => $adtype, 
     'adplace' => $adplace, 
     'date'  => $date, 
     'units'  => $units, 
     'price'  => $price, 

     ); 

     $results = $this->model_sale_ad->insert($data);*/ 

     $this->redirect($this->url->link('sale/ad', 'token=' . $this->session->data['token'] . $url, 'SSL')); 
    } 


} 



} 

    ?> 

這是我的模型:

 <?php 

    class ModelSaleAd extends Model{ 

public function insert($data) 
{ 
    $this->db->query("INSERT INTO " . DB_PREFIX . "ad SET customer = '" 
    .$this->db->escape($data['customer']) . "',adtype = '" .$this->db->escape($data['adtype']) . "',adplace = '" . $this->db->escape($data['adplace']) ."',date = NOW()'" . "',units = '".(int)$data['units'] ."',price = '".(int)$data['price']."')"); 


} 
    } 
+0

告訴我們'$ this-> request-> post'裏面有什麼? – maialithar 2012-04-30 12:28:33

回答

0

嘗試public function insert看着$data['customer']類型的變量,例如var_dump($data)。它可能很簡單,因爲你缺少數組中的變量以及生成缺少的sql時。

相關問題