Post by OpenCartProgrammer » Fri Aug 26, 2016 11:36 pm

I would appreciate any help I can get.
In my header.php file,acting as the parent, I have:

Code: Select all

$this->data['custom_info'] = $this->getChild('module/sample/getInformation',$this->data['information_id']);
var_dump($this->data['custom_info']);
I have a function in in the child module catalog/controller/module/sample.php file

Code: Select all

function getInformation($information_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "custom_information WHERE information_id = '" . (int)$information_id . "'");
return $query->rows;
	}
unfortunately, var_dump shows a value of null in $this->data['custom_info']. I thought I was able to use getchild to pass data from a child function to the parent controller
Any help would be quite appreciated


Posts

Joined
Fri Aug 26, 2016 11:26 pm

Post by qahar » Fri Aug 26, 2016 11:47 pm

Try this

Code: Select all

$this->getChild('module/sample/getInformation', array($this->data['information_id'])); 
And next time please inform your OpenCart version. Because in OC 2, it's change to $this->load->controller()

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by OpenCartProgrammer » Mon Aug 29, 2016 1:25 pm

Qahar,

It's version 1.5.6.4. I appreciate your response. Unfortunately, that didn't do it. The alteration to array($this->data['information_id']) in fact stopped the passing of the $information_id value to the getInformation function. Putting it back to how it was, when I have the getInformation function within sample.php var_dump query->rows it shows the data. However, $this->data['custom_info'] is simply not showing the query->rows data in header.php with return query->rows; in sample.php. I appreciate any further assistance


Posts

Joined
Fri Aug 26, 2016 11:26 pm

Post by qahar » Tue Aug 30, 2016 1:31 pm

Since the arguments is passed as array, you need to adapt your code into

Code: Select all

function getInformation($param) {
  $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "custom_information
                              WHERE information_id = '" . (int)$param[0] . "'");

  return $query->rows;
} 

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by OpenCartProgrammer » Wed Aug 31, 2016 2:55 am

Unfortunately, I think I am missing your line of thought. For me the issue does not seem to be with the child function receiving the arguments, but with it returning the data to the parent function. I think what I am going to do to at least get somewhere with this is instead of returning $query->rows in the child function, storing it as session data:
$this->session->data['custom_info'] = $query->rows;

and in the parent:
var_dump($this->session->data['custom_info']) does now show data.

I appreciate the time you took to give assistance


Posts

Joined
Fri Aug 26, 2016 11:26 pm

Post by qahar » Wed Aug 31, 2016 6:38 am

Ah yes, I missunderstand it.

I think returning data with getChild is not possible for Oc 1.5.x, you can use model instead of passing it through session

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia
Who is online

Users browsing this forum: No registered users and 4 guests