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
0

You can use

Mage::getModel('modulename/modulename')->yourMethod();
1
  • I don't understand, I want to get data from the database inside the Model – characterError Jul 6 '17 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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.