Reputation: 16204
Im working on a pre created joomla component which using the MVC Architecture, My problem like this:
In Models i have a .php
file with database fetch function as
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
class class_name extends JModel
{
var $_data;
function getlast_year(){
$query = 'SELECT year FROM `table` ORDER BY year DESC LIMIT 0,1';
$this->_db->setQuery( $query );
return $this->_db->loadResult();
}
}
I added a new function to the same class file: (I have updated the table columns too in MVC /tables)
as:
function getAttendenceData()
{
$query="SELECT id,octSec,octNin,octSect,octSec,octTwent FROM `table`";
$this->_db->setQuery( $query );
//$this->_data = $this->_db->loadObjectList();
$this->_data = $this->_db->loadObject();
return $this->_db->loadObjectList();
}
but in view i cant still access the fetched data from the above new function but older functions are working property
Upvotes: 0
Views: 448
Reputation: 1825
Isn't the problem that you are attempting to fetch the data twice?
With this line you retrieve it and store it locally in the class's _data variable.
$this->_data = $this->_db->loadObject();
With this line you attempt to retrieve the data again but you've already retrieved it (if there was only one result). You therefore are probably returning a false
return $this->_db->loadObjectList();
You should probably return $this->_data at the end of the function - assuming the original function you are copying was indeed functional.
Upvotes: 1
Reputation: 3373
This is not an actual answer but response to the comment.
First in your view.html.php
file, you'll have to retrieve data from the model.
$attendance_data = & $this->get('AttendenceData');
This'll give you the object list as you are returning from your getAttendenceData() function.
Now assign it to a view variable (lets say data
).
$this->assignRef('data', $attendance_data);
Now you can access this data in your view:
foreach($data as $r)
{
echo $r->id;
}
Upvotes: 1