I am developing a website; which the users can add cars and mobiles with an one registration account. However, I have on the right and on the left boxes for the top hits (cars,mobiles), and in the middle I have the recently added cars and mobiles. I split out the top hits into elements, and the elements are topCars, topMobiles.I was thinking to write two functions to do my stuff. Both functions should be generic, because in the future we might add some other services like software or movies. However The first function will get the recent cars, or mobiles... etc, and that will be published in the middle of my home page. The second function should get the top hits for (cars, mobiles, movies.... etc). I wrote the following code :
class AppController extends Controller
{
var $uses = array('Car','Mobile');
function Controler()
{
App::import('Core', 'Sanitize');
}
function beforeRender(){
$this->getLatestData();
}
function beforeFilter() {
$this->getTopData();
}
function getLatestData(){
$latestCars = $this->Car->find('all', array('order' => array('id' => 'desc'),
'limit' => 7));
$latestMobiles = $this->Mobile->find('all', array('order' => array('id' => 'desc'),
'limit' => 7));
$this->set('cars',$latestCars);
$this->set('mobiles',$latestMobiles);
}
function getTopData($item){ // to get the top hits
$top = $this->$item->find('all', array('order' => array('hits' => 'asc'),
'limit' => 3));
$this->set($item,$top);
}
}
My code works fine for the latest added items fine, but when I try to get the top hits it returns the error. Please help me to know how to make it works Thanks