// Load the model for the component $model = JModelLegacy::getInstance('MyComponentModel'); // Retrieve data from the database $data = $model->getData(); // Do something with the data echo $data[0]->title;
// Load the model for the component $model = JModelLegacy::getInstance('MyComponentModel'); // Set the pagination options $limit = JFactory::getApplication()->input->getInt('limit', 10); $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0); $model->setState('list.start', $limitstart); $model->setState('list.limit', $limit); // Retrieve data from the database with pagination $data = $model->getItems(); // Do something with the data (display it on the page, etc.)Here, we first create an instance of the JModelLegacy class for our component, then set the pagination options using the `setState()` method. We can then retrieve data from the database using the `getItems()` method, which will automatically apply the pagination options. Finally, we can do something with the data, such as display it on the page. Both of these examples demonstrate the versatility and power of JModelLegacy for interacting with Joomla's framework and database. JModelLegacy is a part of the Joomla CMS libraries.