如何在MVC概念中显示控制器数组值


how to display controller array values in mvc concept?

未定义变量类别和未定义变量i.出现错误,我无法显示控制器中的数组值,请帮助我如何解决此错误这是我的header.php控制器文件:

            <?php
        class ControllerCommonHeader extends Controller {
            public function index() {
                $data['title'] = $this->document->getTitle();
                if ($this->request->server['HTTPS']) {
                    $server = $this->config->get('config_ssl');
                } else {
                    $server = $this->config->get('config_url');
                }
                $data['base'] = $server;
                $data['description'] = $this->document->getDescription();
                $data['keywords'] = $this->document->getKeywords();
                $data['links'] = $this->document->getLinks();
                $data['styles'] = $this->document->getStyles();
                $data['scripts'] = $this->document->getScripts();
                $data['lang'] = $this->language->get('code');
                $data['direction'] = $this->language->get('direction');
                if ($this->config->get('config_google_analytics_status')) {
                    $data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
                } else {
                    $data['google_analytics'] = '';
                }
                $data['name'] = $this->config->get('config_name');
                if (is_file(DIR_IMAGE . $this->config->get('config_icon'))) {
                    $data['icon'] = $server . 'image/' . $this->config->get('config_icon');
                } else {
                    $data['icon'] = '';
                }
                if (is_file(DIR_IMAGE . $this->config->get('config_logo'))) {
                    $data['logo'] = $server . 'image/' . $this->config->get('config_logo');
                } else {
                    $data['logo'] = '';
                }
                $this->load->language('common/header');
                $data['text_home'] = $this->language->get('text_home');
                $data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
                $data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
                $data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
                $data['text_account'] = $this->language->get('text_account');
                $data['text_register'] = $this->language->get('text_register');
                $data['text_login'] = $this->language->get('text_login');
                $data['text_order'] = $this->language->get('text_order');
                $data['text_transaction'] = $this->language->get('text_transaction');
                $data['text_download'] = $this->language->get('text_download');
                $data['text_logout'] = $this->language->get('text_logout');
                $data['text_checkout'] = $this->language->get('text_checkout');
                $data['text_category'] = $this->language->get('text_category');
                $data['text_all'] = $this->language->get('text_all');
                $data['home'] = $this->url->link('common/home');
                $data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
                $data['logged'] = $this->customer->isLogged();
                $data['account'] = $this->url->link('account/account', '', 'SSL');
                $data['register'] = $this->url->link('account/register', '', 'SSL');
                $data['login'] = $this->url->link('account/login', '', 'SSL');
                $data['order'] = $this->url->link('account/order', '', 'SSL');
                $data['transaction'] = $this->url->link('account/transaction', '', 'SSL');
                $data['download'] = $this->url->link('account/download', '', 'SSL');
                $data['logout'] = $this->url->link('account/logout', '', 'SSL');
                $data['shopping_cart'] = $this->url->link('checkout/cart');
                $data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
                $data['contact'] = $this->url->link('information/contact');
                $data['telephone'] = $this->config->get('config_telephone');
                $status = true;
                if (isset($this->request->server['HTTP_USER_AGENT'])) {
                    $robots = explode("'n", str_replace(array("'r'n", "'r"), "'n", trim($this->config->get('config_robots'))));
                    foreach ($robots as $robot) {
                        if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
                            $status = false;
                            break;
                        }
                    }
                }

        $this->load->model('catalog/manufacturer');
        $data['categories'] = array();
        $results = $this->model_catalog_manufacturer->getManufacturers(); //here getting manufacturer values from database.
        foreach ($results as $result) {
            if (is_numeric(utf8_substr($result['name'], 0, 1))) {
                $key = '0 - 9';
            } else {
                $key = utf8_substr(utf8_strtoupper($result['name']), 0, 1);
            }
            if (!isset($data['categories'][$key])) {
                $data['categories'][$key]['name'] = $key;
            }
        $data['categories'][$key]['manufacturer'][] = array( //i can't able to display this array values
                'name' => $result['name'],
                'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
            );
        }
                // Menu
                $this->load->model('catalog/category');
                $this->load->model('catalog/product');
                $data['categories'] = array();
                $categories = $this->model_catalog_category->getCategories(0);
                foreach ($categories as $category) {
                    if ($category['top']) {
                        // Level 2
                        $children_data = array();
                        $children = $this->model_catalog_category->getCategories($category['category_id']);
                        foreach ($children as $child) {
                            $filter_data = array(
                                'filter_category_id'  => $child['category_id'],
                                'filter_sub_category' => true
                            );
                            $children_data[] = array(
                                'name'  => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                                'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                            );
                        }
                        // Level 1
                        $data['categories'][] = array(
                            'name'     => $category['name'],
                            'children' => $children_data,
                            'column'   => $category['column'] ? $category['column'] : 1,
                            'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
                        );
                    }
                }
                $data['language'] = $this->load->controller('common/language');
                $data['currency'] = $this->load->controller('common/currency');
                $data['search'] = $this->load->controller('common/search');
                $data['cart'] = $this->load->controller('common/cart');
                // For page specific css
                if (isset($this->request->get['route'])) {
                    if (isset($this->request->get['product_id'])) {
                        $class = '-' . $this->request->get['product_id'];
                    } elseif (isset($this->request->get['path'])) {
                        $class = '-' . $this->request->get['path'];
                    } elseif (isset($this->request->get['manufacturer_id'])) {
                        $class = '-' . $this->request->get['manufacturer_id'];
                    } else {
                        $class = '';
                    }
                    $data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
                } else {
                    $data['class'] = 'common-home';
                }
                if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
                    return $this->load->view($this->config->get('config_template') . '/template/common/header.tpl', $data);
                } else {
                    return $this->load->view('default/template/common/header.tpl', $data);
                }
            }
        }
这是我的html代码:
<li><a href="<?php echo $category['manufacturer'][$i]['href']; ?>"><?php echo $category['manufacturer'][$i]['name']; ?></a></li>

正如我在控制器中所理解的那样,您将$key作为字符串'0 - 9'或作为从$result['name']获得的单个大写字母。

如果Ok, now?

你从哪里得到的$i ?因为我没在你的控制器上看到它!你的html行在$categories foreach循环中吗?

要使$i在视图中可访问,在控制器中必须有$data['i'] = something;