我有一个表单……当我单击插入按钮时,值必须存储在数据库中……但是在我的表单中,当我打开表单时,默认值存储在 db 中。我在 php mvc 架构中开发所有这些。
这是我的控制器:
<?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->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->load->model('sale/ad');
$this->insert();
$this->response->setOutput($this->render());
}
public function insert() {
$customer = $_POST['entry_customer_name'];
$adtype = $_POST['column_name'];
$adplace=$_POST['column_place'];
$date=$_POST['column_date'];
$units=$_POST['column_units'];
$price=$_POST['column_price'];
$data=array();
$data = array (
'customer' => $customer,
'adtype' => $adtype,
'adplace' => $adplace,
'date' => $date,
'units' => $units,
'price' => $price,
);
$this->model_sale_ad->insert($data);
}
}
?>
当我单击插入按钮时,必须调用 insert() 函数....帮助我如何编写这样的...