I created my own module, the table is created in the database and in a phtml I can call:
$res = $model->getExample();
and effectively it function is called.
In Model:
protected function _construct() {
$this->_init('table_name', 'column_id');
}
public function getExample(){
$result = $this->getData();
}
but 'result' is empty and I know there're data in a database, so... what's the problem?
CLUES
gettype($this) // is object
$this->load() // Call to a member function load() on a non-object
Mohit Rane
2,0001 gold badge17 silver badges52 bronze badges
asked Jul 6, 2017 at 11:29
2 Answers 2
You can use
Mage::getModel('modulename/modulename')->yourMethod();
answered Jul 6, 2017 at 11:38
-
I don't understand, I want to get data from the database inside the ModelcharacterError– characterError2017年07月06日 11:47:27 +00:00Commented Jul 6, 2017 at 11:47
To get Data from your model you can call your model directly
//If you want to load from ID
Mage::getModel('modulename/modulename')->load($id);
// If You want collection
Mage::getModel('modulename/modulename')->getCollection();
// If you want from a method defined in your model
// In your model Define a function
public function getMyData(){
return $this->getCollection(); // Varien Object
// return return $this->getCollection()->getData(); // Array
}
Mage::getModel('modulename/modulename')->getMyData();
answered Jul 6, 2017 at 12:12
default