0

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

6
  • 1. First check if you are actually getting some data from the query. do print_r($this->_db->loadObjectList()) in above function. 2. If yes, then what's the code in the view where you're accessing this data? Commented Dec 6, 2011 at 3:39
  • Thanks Vikk query works fine. i access data as $this->data as $r then $r->id data fetches from older functions are fetched fine only the problem with the new function Commented Dec 6, 2011 at 3:42
  • In that case, can you post the code where you're retrieving data from model and assigning it to the view variable? This should be in the view.html.php file of your view. Commented Dec 6, 2011 at 3:55
  • @Vikk This Components is so complex not possible to post the code :-) .. btw can u tell me how to retrieving data from model and assigning it to the view variable ? Commented Dec 6, 2011 at 4:06
  • @vikk there is some code as $items= & $this->get( 'Data'); Commented Dec 6, 2011 at 4:07

2 Answers 2

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

assignRef is deprecated since Joomla 1.6. See here: stackoverflow.com/questions/14883180/…
1

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.

1 Comment

hi Dean thanks a lot for the answer it was not the issue .. its was as Vikk was told ! thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.