I have a model pulling data from two external API's, concatenating the returned arrays, and a view template that displays it. I have a sub-view that will need only one of the API's.
So my question is this:
What's actually initiating the model request to the API?
The view.html.php, or the view templates?
If it's the view.html.php file, then there's no need for a second model method and I can just reuse the request.
If the view template is pulling it, then cutting the API requests in half would make the request faster.
models/domains.php
public function getPrices() {
$dispatcher = JEventDispatcher::getInstance();
$prices = $dispatcher->trigger('getData', 'products/customer-price.json');
$cats = $dispatcher->trigger('getData', 'products/category-keys-mapping.json');
$result = array();
$result[]['product'] = $cats[0];
$result[]['prices'] = $prices[0];
if (isset($cats[0]['status'])) {
JError::raiseError(400, $cats[0]['ERROR']);
return false;
} else {
if (!isset($this->prices)) {
$this->prices = $result;
}
return $this->prices;
}
}
public function getTlds() {
$dispatcher = JEventDispatcher::getInstance();
$cats = $dispatcher->trigger('getData', 'products/category-keys-mapping.json');
$dispatcher->trigger('end');
$result = array();
$result[]['product'] = $cats[0];
if (isset($cats[0]['status'])) {
JError::raiseError(400, $cats[0]['ERROR']);
return false;
} else {
if (!isset($this->tlds)) {
$this->tlds= $result;
}
return $this->tlds;
}
}
views/domains/view.html.php
function display($tpl = null) {
// Assign data to the view
$this->prices = $this->get('prices');
$this->tlds = $this->get('tlds');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');
return false;
}
// Display the view
parent::display($tpl);
}