Undefined index Opencart in home.php -


opencart version 1.5.5.1

i add code: in home.php display in home.tpl

controller :

<?php   class controllercommonhome extends controller { public function index() {     $this->document->settitle($this->config->get('config_title'));     $this->document->setdescription($this->config->get('config_meta_description'));     $this->data['heading_title'] = $this->config->get('config_title');      $this->dell(); // custom      if (file_exists(dir_template . $this->config->get('config_template') . '/template/common/home.tpl')) {         $this->template = $this->config->get('config_template') . '/template/common/home.tpl';     } else {         $this->template = 'default/template/common/home.tpl';     }      $this->children = array(         'common/column_left',         'common/column_right',         'common/content_top',         'common/content_bottom',         'common/footer',         'common/header'     );      $this->response->setoutput($this->render()); }  // custom start here ------------------------------- protected function dell() {     $this->document->settitle($this->config->get('config_title'));     $this->document->setdescription($this->config->get('config_meta_description'));     $this->data['heading_title'] = $this->config->get('config_title');     $this->load->model('catalog/item');      for($i=1; $i<=7; $i++)  // start 1     {         $menu = array(             'menu'  => $i,         );         $results = $this->model_catalog_item->select_id_dell($menu);              if(isset($results)){             $this->data['dell'][] = array(             $results['show_product_id'],             $results['head_text'],             $results['title_text'],             );         }         $this->data['item'] = $this->model_catalog_item->select_item_dell($results);             foreach($this->data['item'] $id){             $all_data = $this->model_catalog_item->select_description_dll($id);             if(isset($all_data)){                 $this->data['product_dell'][$i][] = array(                         $all_data['name'],                         $all_data['shortdescription'],                         $all_data['image'],                         $all_data['price'],                  );                 //var_dump($this->data['product_dell'][1][1]);             }         }     } } } ?> 

edit : model

public function select_description_dll($id){     $sql = "select * " . db_prefix . "product p left join " . db_prefix . "product_description pd on (p.product_id = pd.product_id) left join " . db_prefix . "product_to_category p2c on (p.product_id = p2c.product_id)  pd.language_id = '" . (int)$this->config->get('config_language_id') . "' && p.product_id = '" . $this->db->escape($id['product_id']) . "' group p.product_id";     //echo $sql; exit;     $query = $this->db->query($sql);     return $query->row; } 

i add code $this->dell();, try var_dump($this->data['product_dell'][1][1]) , it's working.

array(1) { [0]=> array(4) { [0]=> string(5) "aaaaa" [1]=> string(2) "aa" [2]=> string(3) "aaa" [3]=> string(2) "00" } }  

but in display home.tpl it's error http://s1064.photobucket.com/user/blackarch01/media/2016-02-25_14-42-09_zpsqvd3odia.png.html?sort=3&o=0

in case store data array in $product[1][1][1] until $product[7][7][7]

1st [1] grup menu 1-7

2st [1] sub menu (e.g 1 menu have 5 child)

3st [1] description 1 child (like name,dll)

then in view using for display , it's work $name = $product_dell[1][$i][0];

it's write undefined index in 'name' it's mean in controller $all_data['name'], , too.

when try var_dump($product_dell[1][1]); in view, it's working (success passing variable), idwk why it's error , how fix ???

thank comment, got answers after keep trying.

in open cart (in case) after passing data variable model this

 $all_data = $this->model_catalog_item->select_description_dll($id); 

i cant passing data ( take data database ):

 if(isset($all_data)){     $this->data['product_dell'][$i][] = array(          $all_data['name'],         // error undefined index name !!!          $all_data['shortdescription'], // error undefined index shoertdescription !!!          $all_data['image'],        // error undefined index image !!!          $all_data['price'],       // error undefined index price !!!     );  } 

so change variable :

if(isset($all_data['name']))     $name = $all_data['name']; else     $name = null; 

then store again array :

if(isset($all_data)){     $this->data['product_dell'][$i][] = array(         $name,         $.....,     ); } 

and it's working :)


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -