-1

我有一个表单……当我单击插入按钮时,值必须存储在数据库中……但是在我的表单中,当我打开表单时,默认值存储在 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() 函数....帮助我如何编写这样的...

4

1 回答 1

0

你的想法似乎有点混乱。您不能在客户端运行 PHP 代码(即:当用户单击按钮时)

您可以做的是对您的 php 页面的 AJAX 调用,该页面将插入您的记录。
许多当前的框架都有库来轻松管理 AJAX 操作。

您可以在此处进一步阅读:http ://en.wikipedia.org/wiki/Ajax_(programming )

于 2012-04-30T12:20:40.090 回答