@mrzgt

Как определить переменную?

Есть код, но не как не могу определить переменную $child_visible
<?php if($child_visible){ ?>
			<?php if ($category['children']) { ?>
					<ul class="list-unstyled">
             <?php foreach (array_slice($category['children'], 0, $count_child) as $child) { ?>
			    <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
                <?php } ?>
				<li><a style="color: red;" href="<?php echo $category['href']; ?>"><?php echo "-> смотреть все категории <-"; ?></a></li>
              </ul>
				     <?php } ?>
  <?php } ?>


сам PHP
<?php
class ControllerModuleCategoryWall extends Controller {
    public function index($setting) {
		
		$check=array();
	    $check = $setting['category_wall_cat'];
	

        $this->load->language('module/category_wall');
        $data['heading_title'] = $this->language->get('heading_title');
		
        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string) $this->request->get['path']);
        } else {
            $parts = array();
        }
		
        if (isset($parts[0])) {
            $data['category_id'] = $parts[0];
        } else {
            $data['category_id'] = 0;
        }
		
        if (isset($parts[1])) {
            $data['child_id'] = $parts[1];
        } else {
            $data['child_id'] = 0;
        }
		
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $data['categories'] = array();
        $categories = $this->model_catalog_category->getCategories(0);
        $this->load->model('tool/image');
		
        foreach ($categories as $category) {
						$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
					);
					
				if (isset($check) && (in_array($category['category_id'], $check ))) {	
					$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'])
					);
				 }	
				}
           
	

	
            if ($category['image']) {
                $image = $this->model_tool_image->resize($category['image'], $setting['width'], $setting['height']);
            } else {
                $image = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
            }
			
				$filter_data = array(
					'filter_category_id'  => $category['category_id'],
					'filter_sub_category' => true
					);
					
			    if (isset($check) && (in_array($category['category_id'], $check ))) {	
            $data['categories'][] = array(
                'name' => $category['name']. ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
				'children' => $children_data,
                'image' => $image,
                'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
		       }
        }
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category_wall.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/module/category_wall.tpl', $data);
        } else {
            return $this->load->view('default/template/module/category_wall.tpl', $data);
        }
    }
}
  • Вопрос задан
  • 234 просмотра
Пригласить эксперта
Ответы на вопрос 1
@heartdevil
плыву как воздушный шарик
Вы вот это где выводите?

<?php echo $entry_child; ?>


<?php if ($child_visible) { ?>

<?php echo $text_yes; ?>
<?php } else { ?>

<?php echo $text_yes; ?>
<?php } ?>


<?php if (!$child_visible) { ?>

<?php echo $text_no; ?>
<?php } else { ?>

<?php echo $text_no; ?>
<?php } ?>


Если это раньше вызывается, чем объявление переменной в контроллере, тогда может возникнуть такая ошибка.

Вот этот код объявления переменной и хранение в data должен быть раньше, чем любой вызов.
if (isset($this->request->post['child_visible'])) {
$data['child_visible'] = $this->request->post['child_visible'];
} elseif (!empty($module_info)) {
$data['child_visible'] = $module_info['child_visible'];
} else {
$data['child_visible'] = "1";
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы