Post by Grandstand » Thu Apr 23, 2015 10:29 pm

I need to add several private functions to the a few admin controller files. Rather than add a bunch of duplicate code with VQmod I was hoping to a link to "module/common_functions.php" vqmod and the access the functions that way, but I'm not sure how to do that.

I tried:

Code: Select all

$this->getChild('controller/module/common_functions.php'); 
and

Code: Select all

$this->getChild('module/common_functions.php');
But get Error: Could not load controller

I also tried

Code: Select all

include_once 'controller/module/common_functions.php';
$this->FunctionIwantToCall(); 
but it won't find the function.

Am I on the right track?

New member

Posts

Joined
Sat Aug 27, 2011 8:03 am

Post by rph » Thu Apr 23, 2015 11:18 pm

Like below:

Code: Select all

// OpenCart 1.x
$this->children = array(
    'directory/file/method'
);

// OpenCart 2.x
$data['foo'] = $this->load->controller('directory/file/method');
 
The method call is optional.

Examples:

Code: Select all

// OpenCart 1.x
$this->children = array(
    'common/header',
    'catalog/product/review'
);

// OpenCart 2.x
$data['header'] = $this->load->controller('common/header');
$data['review'] = $this->load->controller('catalog/product/review');
 
Unless you're trying to get a generated view you should probably consider using the model:

Code: Select all

// OpenCart all versions
$this->load->model('directory/file');
$this->model_directory_file->methodCall($prams);
 
Example:

Code: Select all

$this->load->model('catalog/prodct');
$this->model_catalog_product->getProduct($product_id);
 

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by Grandstand » Fri Apr 24, 2015 1:51 am

Thank you for the clarification on the two versions. That is very helpful. Currently I am working on 1.6 so I would think

$this->children = array('dir/file/method'); is probably my best bet, but since its a private function I'm running into errors. Do I have to make this a public function in order to call it from an outside file?

New member

Posts

Joined
Sat Aug 27, 2011 8:03 am

Post by rph » Fri Apr 24, 2015 2:14 am

Yes. Private methods are only available from within their class.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska
Who is online

Users browsing this forum: No registered users and 4 guests