0

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

0

You can use

Mage::getModel('modulename/modulename')->yourMethod();
answered Jul 6, 2017 at 11:38
1
  • I don't understand, I want to get data from the database inside the Model Commented Jul 6, 2017 at 11:47
0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.