Undefined variable category and Undefined variable i. error occurs .I cannot display array values from controller,so please help me how to solve this error
This my header.php controller file:
<?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);
}
}
}
And this my html code:
<li><?php echo $category['manufacturer'][$i]['name']; ?></li>
As I understand in controller you seek $key as a string '0 - 9' or as a single uppercase letter gotten from $result['name'].?
If Ok, now?
Where did you get the $i from? Because I haven't seen it in your controller! And is your html line in a $categories foreach loop?
For $i to be accesible in your view, in your controller you would have to have $data['i'] = something;
This my manufacturer.php(controller file)
<?php
class ControllerProductManufacturer extends Controller {
public function index() {
$this->load->language('product/manufacturer');
$this->load->model('catalog/manufacturer');
$this->load->model('tool/image');
$this->document->setTitle($this->language->get('heading_title'));
$data['heading_title'] = $this->language->get('heading_title');
$data['text_index'] = $this->language->get('text_index');
$data['text_empty'] = $this->language->get('text_empty');
$data['button_continue'] = $this->language->get('button_continue');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer')
);
$data['categories'] = array();
$results = $this->model_catalog_manufacturer->getManufacturers();
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(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
$data['continue'] = $this->url->link('common/home');
$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/product/manufacturer_list.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/manufacturer_list.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/manufacturer_list.tpl', $data));
}
}
public function info() {
$this->load->language('product/manufacturer');
$this->load->model('catalog/manufacturer');
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['manufacturer_id'])) {
$manufacturer_id = (int)$this->request->get['manufacturer_id'];
} else {
$manufacturer_id = 0;
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit'])) {
$limit = $this->request->get['limit'];
} else {
$limit = $this->config->get('config_product_limit');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_brand'),
'href' => $this->url->link('product/manufacturer')
);
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if ($manufacturer_info) {
$this->document->setTitle($manufacturer_info['name']);
$this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id']), 'canonical');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $manufacturer_info['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url)
);
$data['heading_title'] = $manufacturer_info['name'];
$data['text_empty'] = $this->language->get('text_empty');
$data['text_quantity'] = $this->language->get('text_quantity');
$data['text_manufacturer'] = $this->language->get('text_manufacturer');
$data['text_model'] = $this->language->get('text_model');
$data['text_price'] = $this->language->get('text_price');
$data['text_weight'] = $this->language->get('text_weight');
$data['text_tax'] = $this->language->get('text_tax');
$data['text_points'] = $this->language->get('text_points');
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$data['text_sort'] = $this->language->get('text_sort');
$data['text_limit'] = $this->language->get('text_limit');
$data['button_cart'] = $this->language->get('button_cart');
$data['button_wishlist'] = $this->language->get('button_wishlist');
$data['button_compare'] = $this->language->get('button_compare');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_list'] = $this->language->get('button_list');
$data['button_grid'] = $this->language->get('button_grid');
$data['compare'] = $this->url->link('product/compare');
$data['products'] = array();
$filter_data = array(
'filter_manufacturer_id' => $manufacturer_id,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'weight' => $result['weight'],
'weight_class'=> $result['weight_class'],
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url)
);
}
$url = '';
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = array();
$data['sorts'][] = array(
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url)
);
if ($this->config->get('config_review_status')) {
$data['sorts'][] = array(
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=DESC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=rating&order=ASC' . $url)
);
}
$data['sorts'][] = array(
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url)
);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = array();
$limits = array_unique(array($this->config->get('config_product_limit'), 25, 50, 75, 100));
sort($limits);
foreach($limits as $value) {
$data['limits'][] = array(
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value)
);
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$data['continue'] = $this->url->link('common/home');
$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/product/manufacturer_info.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/manufacturer_info.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/product/manufacturer_info.tpl', $data));
}
} else {
$url = '';
if (isset($this->request->get['manufacturer_id'])) {
$url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_error'),
'href' => $this->url->link('product/manufacturer/info', $url)
);
$this->document->setTitle($this->language->get('text_error'));
$data['heading_title'] = $this->language->get('text_error');
$data['text_error'] = $this->language->get('text_error');
$data['button_continue'] = $this->language->get('button_continue');
$data['continue'] = $this->url->link('common/home');
$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
$data['header'] = $this->load->controller('common/header');
$data['footer'] = $this->load->controller('common/footer');
$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');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/error/not_found.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/error/not_found.tpl', $data));
}
}
}
}
And this my html code(manufacturer.tpl file)
this code get all manufactures from db and displays in frontend via manufacturer.php(controller).
<?php echo $category['manufacturer'][$i]['name']; ?>
BUT i want to display the above html code into my header.tpl(html)file but it displays undefined variable.i cannot access that manufacturer,so please help me how to display manufacturer value in header.tpl file using my header.php(controller).
this my header.php controller code:
<?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;
}
}
}
// 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);
}
}
}
And this my header.tpl file:
<li><?php echo $category['manufacturer'][$i]['name']; ?></li>
Here is your header.php code
<?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;
}
}
}
// 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);
}
}
// I have added this
$data['categories'] = array();
$results = $this->model_catalog_manufacturer->getManufacturers();
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(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
}
I believe that sessions would be the best solution for this
You can fetch and store all data in your model only and then put it in $_SESSION super-variable
$this->load->library('session');
$_SESSION['anything']=$your-data;
echo $_SESSION['anything'];
this will work please check..
<?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['manufacturer'] = $this->language->get('manufacturer');
$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');
$results = $this->model_catalog_manufacturer->getManufacturers();
$data['manufacturer'] = array();
foreach ($results as $result) {
$data['manufacturer'][] = array(
'name' => $result['name'],
'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id'])
);
}
//print_r($data['manufacturer']);exit;
// 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);
}
}
}
put this tpl code into your file:
<?php foreach ($manufacturer as $manufacturers) { ?>
<?php if ($manufacturers['name']){ ?>
<li><?php echo $manufacturers['name']; ?></li>
<?php }?>
<?php }?>
It will depend on the circumstances. If you want to retain the data for some time, then session data would be the way to go. However, if you only need to use it once, flash data might be more appropriate.
First step would be to initialize the session library:
$this->load->library('session');
Then store the information in flash data:
$this->session->set_flashdata('item', $myVar);
Finally, in the second controller, fetch the data:
$myVar = $this->session->flashdata('item');
Obviously this would mean you'd have to either initialize the session library again from the second controller, or create your own base controller that loads the session library and have both of your controllers inherit from that one.
For some reason my status and date added are not displaying on my table in codeigniter. I have got the username working fine but should be able to see date added and status both are working fine in database. image of my user http://s20.postimg.org/7719crcl9/user.png
Status in the database when enabled is "1" But should show text enabled.
How do I get both my status and date added working?
Model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->helper('date');
}
public function getTotalUsers() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . $this->db->dbprefix . "user`");
return $query->row('total');
}
public function getUsers($data = array()) {
$sql = "SELECT * FROM `" . $this->db->dbprefix . "user`";
$sort_data = array(
'username',
'status',
'date_added'
);
if (trim($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY username";
}
if (trim($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
$query = $this->db->query($sql);
return $query->result_array();
}
}
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends Controller {
private $error = array();
public function index() {
$this->lang->load('user/user', 'english');
$this->load->model('user/user_model');
$this->getList();
}
public function getList() {
if (null !==($this->input->get('sort'))) {
$sort = $this->input->get('sort');
} else {
$sort = 'username';
}
if (null !==($this->input->get('order'))) {
$order = $this->input->get('order');
} else {
$order = 'ASC';
}
if (null !==($this->input->get('page'))) {
$page = $this->input->get('page');
} else {
$page = 1;
}
$url = '';
if (null !==($this->input->get('sort'))) {
$url .= '&sort=' . $this->input->get('sort');
}
if (null !==($this->input->get('order'))) {
$url .= '&order=' . $this->input->get('order');
}
if (null !==($this->input->get('page'))) {
$url .= '&page=' . $this->input->get('page');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('text_home'),
'href' => site_url('dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('user')
);
$data['insert'] = site_url('user/insert');
$data['delete'] = site_url('user/delete');
$data['users'] = array();
$filter_data = array(
'sort' => $sort,
'order' => $order,
);
$user_total = $this->user_model->getTotalUsers();
$results = $this->user_model->getUsers($filter_data);
foreach ($results as $result) {
$data['users'][] = array(
'user_id' => $result['user_id'],
'username' => $result['username'],
'status' => ($result['status'] ? $this->lang->line('text_enabled') : $this->lang->line('text_disabled')),
'date_added' => date($this->lang->line('date_format_short'), strtotime($result['date_added'])),
'edit' => site_url('user/update', '&user_id=' . $result['user_id'] . $url)
);
}
$data['heading_title'] = $this->lang->line('heading_title');
$data['text_no_results'] = $this->lang->line('text_no_results');
$data['text_confirm'] = $this->lang->line('text_confirm');
$data['column_username'] = $this->lang->line('column_username');
$data['column_status'] = $this->lang->line('column_status');
$data['column_date_added'] = $this->lang->line('column_date_added');
$data['column_action'] = $this->lang->line('column_action');
$data['button_insert'] = $this->lang->line('button_insert');
$data['button_edit'] = $this->lang->line('button_edit');
$data['button_delete'] = $this->lang->line('button_delete');
if (null !==($this->input->post('selected'))) {
$data['selected'] = (array)$this->input->post('selected');
} else {
$data['selected'] = array();
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
if (null !==($this->input->get('page'))) {
$url .= '&page=' . $this->input->get('page');
}
$data['sort_username'] = site_url('user', '&sort=username' . $url);
$data['sort_status'] = site_url('user', '&sort=status' . $url);
$data['sort_date_added'] = site_url('user', '&sort=date_added' . $url);
$url = '';
if (null !==($this->input->get('sort'))) {
$url .= '&sort=' . $this->input->get('sort');
}
if (null !==($this->input->get('order'))) {
$url .= '&order=' . $this->input->get('order');
}
$data['sort'] = $sort;
$data['order'] = $order;
$this->load->view('user/user_list', $data);
}
}
View
<?php if ($users) { ?>
<?php foreach ($users as $user) { ?>
<tr>
<td class="text-center"><?php if (in_array($user['user_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $user['user_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $user['user_id']; ?>" />
<?php } ?></td>
<td class="text-left"><?php echo $user['username']; ?></td>
<td class="text-left"><?php echo $user['status']; ?></td>
<td class="text-left"><?php echo $user['date_added']; ?></td>
<td class="text-right"><i class="fa fa-pencil"></i></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="5"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
I found my problem I had to load my English language file I for got it.
public function index() {
$this->lang->load('user/user', 'english');
$this->lang->load('english', 'english'); // Had to add this
$this->load->model('user/user_model');
$this->getList();
}
I have built an OpenCart module to add "articles" to the site. I have done this by cloning the "information" module and then adapting it to my needs.
I have made a lot of progress - pretty much finished what I set out to do - and everything works fine on my local dev server. Problem is I've pushed it up to the live server and when I enter the article details and press save (in the admin area) it immediately logs me out, and nothing is saved at all.
My feeling is that it has something to do with the token that gets added when I log in because when I save and I get logged out that token number (appended to the url) is different.
I don't know php all that well (have a background in C# and .NET) but generally understand what's going on. I hope someone can help out.
The Controller file for article: (let me know if any other files/info is needed)
class ControllerCatalogArticle extends Controller {
private $error = array();
public function index() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
$this->getList();
}
public function insert() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_catalog_article->addArticle($this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getForm();
}
public function update() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_catalog_article->editArticle($this->request->get['article_id'], $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getForm();
}
public function delete() {
$this->load->language('catalog/article');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/article');
if (isset($this->request->post['selected']) && $this->validateDelete()) {
foreach ($this->request->post['selected'] as $article_id) {
$this->model_catalog_article->deleteArticle($article_id);
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->redirect($this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->getList();
}
private function getList() {
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'id.title';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
$this->data['insert'] = $this->url->link('catalog/article/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['delete'] = $this->url->link('catalog/article/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
$this->data['articles'] = array();
$data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_admin_limit'),
'limit' => $this->config->get('config_admin_limit')
);
$article_total = $this->model_catalog_article->getTotalArticles();
$results = $this->model_catalog_article->getArticles($data);
$this->load->model('catalog/article_category');
foreach ($results as $result) {
$action = array();
$action[] = array(
'text' => $this->language->get('text_edit'),
'href' => $this->url->link('catalog/article/update', 'token=' . $this->session->data['token'] . '&article_id=' . $result['article_id'] . $url, 'SSL')
);
$this->data['articles'][] = array(
'article_id' => $result['article_id'],
'category_id' => $result['category_id'],
'title' => $result['title'],
'sort_order' => $result['sort_order'],
'selected' => isset($this->request->post['selected']) && in_array($result['article_id'], $this->request->post['selected']),
'action' => $action,
'article_category' => $this->model_catalog_article_category->getArticleCategoryTitle($result['category_id'])
);
}
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_no_results'] = $this->language->get('text_no_results');
$this->data['column_title'] = $this->language->get('column_title');
$this->data['column_article_category'] = $this->language->get('column_article_category');
$this->data['column_sort_order'] = $this->language->get('column_sort_order');
$this->data['column_action'] = $this->language->get('column_action');
$this->data['button_insert'] = $this->language->get('button_insert');
$this->data['button_delete'] = $this->language->get('button_delete');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['sort_title'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . '&sort=id.title' . $url, 'SSL');
$this->data['sort_sort_order'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . '&sort=i.sort_order' . $url, 'SSL');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$pagination = new Pagination();
$pagination->total = $article_total;
$pagination->page = $page;
$pagination->limit = $this->config->get('config_admin_limit');
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
$this->data['pagination'] = $pagination->render();
$this->data['sort'] = $sort;
$this->data['order'] = $order;
$this->template = 'catalog/article_list.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function getForm() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['text_default'] = $this->language->get('text_default');
$this->data['text_enabled'] = $this->language->get('text_enabled');
$this->data['text_disabled'] = $this->language->get('text_disabled');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_description'] = $this->language->get('entry_description');
$this->data['entry_meta_title'] = $this->language->get('entry_meta_title');
$this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
$this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
$this->data['entry_abstract'] = $this->language->get('entry_abstract');
$this->data['entry_article_category'] = $this->language->get('entry_article_category');
$this->data['entry_store'] = $this->language->get('entry_store');
$this->data['entry_keyword'] = $this->language->get('entry_keyword');
$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
$this->data['entry_status'] = $this->language->get('entry_status');
$this->data['entry_layout'] = $this->language->get('entry_layout');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['tab_general'] = $this->language->get('tab_general');
$this->data['tab_data'] = $this->language->get('tab_data');
$this->data['tab_design'] = $this->language->get('tab_design');
$this->data['token'] = $this->session->data['token'];
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->error['title'])) {
$this->data['error_title'] = $this->error['title'];
} else {
$this->data['error_title'] = array();
}
if (isset($this->error['description'])) {
$this->data['error_description'] = $this->error['description'];
} else {
$this->data['error_description'] = array();
}
if (isset($this->error['category'])) {
$this->data['error_category'] = $this->error['category'];
} else {
$this->data['error_category'] = array();
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['article_id'])) {
$this->data['action'] = $this->url->link('catalog/article/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
} else {
$this->data['action'] = $this->url->link('catalog/article/update', 'token=' . $this->session->data['token'] . '&article_id=' . $this->request->get['article_id'] . $url, 'SSL');
}
$this->data['cancel'] = $this->url->link('catalog/article', 'token=' . $this->session->data['token'] . $url, 'SSL');
if (isset($this->request->get['article_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$article_info = $this->model_catalog_article->getArticle($this->request->get['article_id']);
}
$this->load->model('localisation/language');
$this->data['languages'] = $this->model_localisation_language->getLanguages();
if (isset($this->request->post['article_description'])) {
$this->data['article_description'] = $this->request->post['article_description'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_description'] = $this->model_catalog_article->getArticleDescriptions($this->request->get['article_id']);
} else {
$this->data['article_description'] = array();
}
$this->load->model('catalog/article');
$this->data['article_categories'] = $this->model_catalog_article->getArticleCategoriesSort();
if (isset($this->request->post['select_categories'])) {
$this->data['category_id'] = $this->request->post['select_categories'];
} elseif (!empty($article_info)) {
$this->data['category_id'] = $article_info['category_id'];
} else {
$this->data['category_id'] = 0;
}
if (isset($this->request->post['status'])) {
$this->data['status'] = $this->request->post['status'];
} elseif (!empty($article_info)) {
$this->data['status'] = $article_info['status'];
} else {
$this->data['status'] = 1;
}
$this->load->model('setting/store');
$this->data['stores'] = $this->model_setting_store->getStores();
if (isset($this->request->post['article_store'])) {
$this->data['article_store'] = $this->request->post['article_store'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_store'] = $this->model_catalog_article->getArticleStores($this->request->get['article_id']);
} else {
$this->data['article_store'] = array(0);
}
if (isset($this->request->post['keyword'])) {
$this->data['keyword'] = $this->request->post['keyword'];
} elseif (!empty($article_info)) {
$this->data['keyword'] = $article_info['keyword'];
} else {
$this->data['keyword'] = '';
}
if (isset($this->request->post['sort_order'])) {
$this->data['sort_order'] = $this->request->post['sort_order'];
} elseif (!empty($article_info)) {
$this->data['sort_order'] = $article_info['sort_order'];
} else {
$this->data['sort_order'] = '';
}
if (isset($this->request->post['article_layout'])) {
$this->data['article_layout'] = $this->request->post['article_layout'];
} elseif (isset($this->request->get['article_id'])) {
$this->data['article_layout'] = $this->model_catalog_article->getArticleLayouts($this->request->get['article_id']);
} else {
$this->data['article_layout'] = array();
}
$this->load->model('design/layout');
$this->data['layouts'] = $this->model_design_layout->getLayouts();
$this->template = 'catalog/article_form.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
private function validateForm() {
if (!$this->user->hasPermission('modify', 'catalog/article')) {
$this->error['warning'] = $this->language->get('error_permission');
}
foreach ($this->request->post['article_description'] as $language_id => $value) {
if ((utf8_strlen($value['title']) < 3) || (utf8_strlen($value['title']) > 64)) {
$this->error['title'][$language_id] = $this->language->get('error_title');
}
if (utf8_strlen($value['description']) < 3) {
$this->error['description'][$language_id] = $this->language->get('error_description');
}
}
if ($this->error && !isset($this->error['warning'])) {
$this->error['warning'] = $this->language->get('error_warning');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
private function validateDelete() {
if (!$this->user->hasPermission('modify', 'catalog/article')) {
$this->error['warning'] = $this->language->get('error_permission');
}
$this->load->model('setting/store');
foreach ($this->request->post['selected'] as $article_id) {
if ($this->config->get('config_account_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_account');
}
if ($this->config->get('config_checkout_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_checkout');
}
if ($this->config->get('config_affiliate_id') == $article_id) {
$this->error['warning'] = $this->language->get('error_affiliate');
}
$store_total = $this->model_setting_store->getTotalStoresByArticleId($article_id);
if ($store_total) {
$this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
}
}
if (!$this->error) {
return true;
} else {
return false;
}
}
}