如何获取多语言表数据?

时间:2017-02-25 07:16:36

标签: php opencart

我正在使用opencart 2.3.0.2。我试图从数据表中获取多个语言数据。但输出结果未正确显示valuetitle

productmark

title  value  language_id  product_id
 1st    2nd       1           42
 3st    4nd       2           42

productmark型号

    public function getmarks($product_id) {

          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "productmark WHERE product_id = '" . (int)$product_id . "'");
          return $query->rows;

    }

   public function getmarksdata($product_id,$language_id) {

          $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "productmark WHERE product_id = '" . (int)$product_id . "' AND language_id='".$language_id."'");
          return $query->rows;

    }

productmark控制器

if (isset($this->request->post['productmark'])) {
            $productmarks = $this->request->post['productmark'];
        } elseif (isset($this->request->get['product_id'])) {
            $productmarks = $this->model_productmark->getmarks($this->request->get['product_id']);
        } else {
            $productmarks = array();
        }

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

        foreach ($productmarks as $key=> $productmark) {   
                foreach ($data['languages'] as $language){

                $productmarks_data = $this->model_productmark->getmarksdata($this->request->get['product_id'],$language['language_id']);

                $data['productmarks'][$key][$language['language_id']] = array(
                    'title' => $productmarks_data['title'],
                    'value' => $productmarks_data['value'],

                ); 

            }

          }

productmark模板

<?php $productmark_row = 0; ?>
      <?php foreach ($productmarks as $productmark) { ?>
              <?php foreach ($languages as $language) { ?>
                       <input type="text" name="productmark[<?php echo $productmark_row; ?>][<?php echo $language['language_id']; ?>][title]" value="<?php echo $productmark[$language['language_id']]['title']; ?>" placeholder="Title" class="form-control" />
                <?php }?>
                <?php foreach ($languages as $language) { ?>
                       <input type="text" name="productmark[<?php echo $productmark_row; ?>][<?php echo $language['language_id']; ?>][value]" value="<?php echo $productmark[$language['language_id']]['value']; ?>" placeholder="Value" class="form-control" />
                 <?php }?>
 <?php $productmark_row++; ?>

0 个答案:

没有答案