0

我是Opencart MVC的新手,我有一个名为 my_account.tpl 的页面。在此页面中显示客户nametin_number

如果客户想要更改他们tin_number只需填写 TIN 号码字段并单击保存,它将更新oc_customer表格。

我试过了,但数据没有更新。

以下视图、模型和控制器代码

查看:my_account.tpl

<form action="<?php echo $action;?>" method="POST" enctype="multipart/form-data" class="form-horizontal">
            <div class="col-md-9 col-lg-6 col-sm-12">

                <?php foreach($customerData as $customer) { ?>

                <div class="form-group">
                    <label>Name:</label>
                    <input type="text" style="display: none" placeholder="ID" name="id" value="<?php echo $result['tin_number'];?>">
                    <input type="text" name="name" value="<?php echo $customer['name']; ?>" placeholder="Name" class="form-control" disabled>
                </div>

                <div class="form-group">
                    <label>TIN Number:</label>
                    <input type="text" name="tin_number" value="<?php echo $customer['tin_number']; ?>" placeholder="TIN Number" class="form-control">
                </div>

                <?php } ?>
                <div class="form-group">
                    <input type="submit" name="save" value="<?php echo 'Save'; ?>" class="btn btn-primary">
                </div>

            </div>
        </form>

控制器:my_account.php

public function edit() {

        /*form edit my_account*/
         if(isset($_GET['tin_number']))
        {
            $tin_number=$_GET['tin_number'];
        }
        $this->load->model('account/customer');
        $data['delivery_point']=$this->model_account_customer->getcustomerId($tin_number);
        $data['action'] = $this->url->link('account/my_account', '', 'SSL');


        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {
            $this->model_account_customer->editCustomerTin($this->request->post);
            $this->response->redirect($this->url->link('account/home', '', 'SSL'));
            echo "<script>javascript: alert('test msgbox')></script>";
        }
        /*form edit my_account*/

}

型号:my_account.php

public function editCustomerTin($data)
    {
         $query = $this->db->query("UPDATE " . DB_PREFIX . "customer set tin_number='".$data['tin_number']."' where customer_id=".$data['id']);
    }
4

1 回答 1

0

我得到了答案,它在另一个函数中工作,见下面的编码

控制器 my_account.php

 public function index() {

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

        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Home'),
            'href' => $this->url->link('common/home')
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Previous'),
            'href' => $this->url->link('common/home', '', 'SSL')
        );


        if (isset($this->session->data['success'])) {
            $data['success'] = $this->session->data['success'];

            unset($this->session->data['success']);
        } else {
            $data['success'] = '';
        }

        $data['heading_title'] = $this->language->get('heading_title');
        $url = '';

        $this->load->model('account/customer');

        //$data['customerData']=array();
        $results=$this->model_account_customer->getCustomerByTin();


        foreach($results as $result)
        {

        $query1 = $this->db->query("SELECT concat(firstname,' ',lastname) as name,tin_number,invoice_no_overwrite FROM " . DB_PREFIX . "customer where customer_id='".$_COOKIE['customerId']."'");
        $customer_name= $query1->row['name'];
        $tin_number= $query1->row['tin_number'];
        $invoice_no_overwrite= $query1->row['invoice_no_overwrite'];



            $data['customerData'][0] = array(
                'name'      => $customer_name,
                'invoice_no_overwrite'=> $invoice_no_overwrite,
                'tin_number'=>$tin_number
                );
        }

        //var_dump($data['CustomerData']);

        /*form edit my_account*/
        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {
           $this->model_account_customer->editCustomerTin($this->request->post);
            $this->response->redirect($this->url->link('account/my_account', '', 'SSL'));
        }

        /*form edit my_account*/

        $data['column_left'] = $this->load->controller('common/column_left');
        $data['column_right'] = $this->load->controller('common/column_right');
        $data['content_top'] = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer'] = $this->load->controller('common/footer');
        $data['header'] = $this->load->controller('common/header');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/my_account.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/my_account.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/account/my_account.tpl', $data));
        }

    }

我不知道它是怎么发生的任何人都可以教我......?

于 2017-03-30T09:35:44.790 回答