foreach 在 opencart 自定义页面中不起作用

foreach not working in opencart custom page

正在创建一个名为 no.tpl 的页面。这里显示客户 firstnamelastnameselect dropdown.

这里是我的代码no.tpl

<select name="customer_id" id="customer" style="width: 325px;margin-bottom:10px" class="form-control">
    <?php foreach($customerData as $customer){ ?>
        <option value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option>
    <?php }?>
</select>

这是我的控制器代码

    <?php

class ControllerSaleno extends Controller {
    private $error = array();
    public function index() {

           $data=$this->request->post;
           $customerId=$data['customer_id'];

        //$this->sendMail($customerId);

        $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');

        //$this->response->setOutput($this->load->view('default/template/product/no.tpl', $data));

        $this->response->setOutput($this->load->view('sale/no.tpl', $data));


        //$data['productsData']=$this->getProductData();
         $customers=$this->getCustomerData();

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


 foreach($customers as $customer)
{
   $data['customerData'][]=array(
'customer_id'=>$customer['customer_id'],
'customer_name'=>$customer['firstname'].' '.$customer['lastname']
);
   //var_dump($data['customerData']);
   //var_dump($customer['firstname']);
}


    }
    public function getCustomerData()
    {

        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer order by firstname asc");
        return $query->rows;
    }

    public function sendMail($customerId)
    {

        $tempArray=array();

      $selectedCustomerId=$customerId;
            $query=$this->db->query("SELECT state FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
            $state=$query->row;





            $querySalesEmail=$this->db->query("SELECT email FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
            $salesPersonEmail1=$querySalesEmail->row;

            $salesPersonEmail= $salesPersonEmail1['email'];


 $queryCustomerName=$this->db->query("SELECT concat(firstname,' ',lastname) as name FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
$customerName=$queryCustomerName->row['name'];






    $To = "radhamani123@gmail.com";
    $Subject = "New Order From " . "'" . $customerName . "'" . date('m/d/Y h:i:s');
    $Headers  = "MIME-Version: 1.0\r\n";
    $Headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $Headers .= "From: No ORder<orders@milkymist.in>\r\n";

   $Message = '';


            $Message .= 'No Order Today';


    if(mail($To, $Subject, $Message, $Headers)){
        echo "success";



    }else{
        echo "failure";
    }




 $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');

        $this->response->setOutput($this->load->view('default/template/product/no.tpl', $data));

    }

}

我在控制器页面做了一些修改

<?php

class ControllerSaleno extends Controller {
    private $error = array();
    public function index() {

           $data=$this->request->post;
           $customerId=$data['customer_id'];

        //$this->sendMail($customerId);

        $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');

        //$this->response->setOutput($this->load->view('default/template/product/no.tpl', $data));

        $this->response->setOutput($this->load->view('sale/no.tpl', $data));


        //$data['productsData']=$this->getProductData();
         $customers=$this->getCustomerData();

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


 foreach($customers as $customer)
{
   $data['customerData'][]=array(
'customer_id'=>$customer['customer_id'],
'customer_name'=>$customer['firstname'].' '.$customer['lastname']
);
   //var_dump($data['customerData']);
   //var_dump($customer['firstname']);
}


         $data['NoOrder']=$this->url->link('sale/order/NoOrder', 'token=' . $this->session->data['token'] , 'SSL'); //added code
         $this->response->setOutput($this->load->view('sale/no.tpl', $data)); //added code

    }
    public function getCustomerData()
    {

        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer order by firstname asc");
        return $query->rows;
    }

    /*no order*/
    public function NoOrder()
    {


        $this->sendMail();
        //$this->response->redirect($_SERVER['HTTP_REFERER']);
    }

    public function sendMail()
    {

        $tempArray=array();

      $selectedCustomerId=$customerId;
            $query=$this->db->query("SELECT state FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
            $state=$query->row;





            $querySalesEmail=$this->db->query("SELECT email FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
            $salesPersonEmail1=$querySalesEmail->row;

            $salesPersonEmail= $salesPersonEmail1['email'];


 $queryCustomerName=$this->db->query("SELECT concat(firstname,' ',lastname) as name FROM " . DB_PREFIX . "customer where customer_id=".$selectedCustomerId);
$customerName=$queryCustomerName->row['name'];






$To = "radhamani123@gmail.com";
   $Subject = "New Order From " . "'" . $customerName . "'" . date('m/d/Y h:i:s');
    $Headers  = "MIME-Version: 1.0\r\n";
    $Headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $Headers .= "From: No ORder<orders@milkymist.in>\r\n";

   $Message = '';


            $Message .= 'No Order Today';


    if(mail($To, $Subject, $Message, $Headers)){
        echo "success";



    }else{
        echo "failure";
    }



        //$this->response->setOutput(json_encode($result));
 $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');

       $this->response->setOutput($this->load->view('sale/noorder.tpl', $data));
        //$this->response->setOutput($this->load->view('sale/no.tpl', $data));

    }
    /*no order*/

}