我有一个表单..当我点击插入按钮时,值必须存储在数据库中.. 但是当我打开表单时,默认值存储在db.i中,我正在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()函数.... 帮我怎么写这个......
答案 0 :(得分:0)
你的想法似乎有点困惑。您无法在客户端运行PHP代码(即:当用户单击按钮时)
你可以做的是对你的php页面进行AJAX调用,插入你的记录 许多当前的框架都有库来轻松管理AJAX操作。
您可以在此处进一步阅读:http://en.wikipedia.org/wiki/Ajax_(programming)