I am trying to call model's method from controller.
controller.php
if($view='myview'){
$model= $this->getModel('mymodel'); //on echo-prints class name of model
$locations= $model->get('Locations');
var_dump($locations);//prints NULL
...
}
mymodel.php
public function getLocations(){
$db=JFactory::getDBO();
$query=$db->getQuery(true);
$query->select('distinct location');
$query->from('#__locations');
$db->setQuery($query);
return $loc = & $db->loadObjectList();
}
Why it's returning NULL in controller, however getLocations()
working fine in view.html.php.
$db = JFactory::getDBO();
works in your model but it's better to define the db connection like so:$db = $this->getDbo();
.