1

Magento custom module model returns empty data array,what would be the issue.I am new to magento.Trying to create custom module.Please help me out.please check below screenenter image description here

/Model/Suites.php:

<?php

class Bespoke_Suites_Model_Suites extends Mage_Core_Model_Abstract{

public function _construct(){
    parent::_construct();
    $this->_init('bespoke_suites/suites');
}

/Model/Resource/Suites.php :

<?php
class Bespoke_Suites_Model_Resource_Suites extends Mage_Core_Model_Resource_Db_Abstract{

public function _construct(){
    //parent::_construct();
    $this->_init('bespoke_suites/suites','suites_id');
}
}

config.xml

.....
<bespoke_suites_resource>
    <class>Bespoke_Suites_Model_Resource</class>
    <entities>
        <suites>
            <table>bespoke_suites</table>
        </suites>
    </entities>
</bespoke_suites_resource>
.....
  • try to dump $model->getData() – Aleksey Razbakov Nov 9 '15 at 13:50
  • @razbakov Fatal error: Call to a member function getData() – Nagendra Nov 9 '15 at 13:58
  • $model = Mage::getModel('bespoke_suites/suites')->load(1); print_r($model->getData()); – Aleksey Razbakov Nov 9 '15 at 14:07
  • @razbakov resource instance is not available means what in this case? – Nagendra Nov 10 '15 at 4:55
3

So have you written any instances to your database?

Then load a specific instance (suite) and view its data:

/** @var Bespoke_Suites_Model_Suites $suite */
$suite = Mage::getModel('bespoke_suites/suites');
// Load suite with suites_id = 1
$suite->load(1);

If you have not yet created any suites, you may do so with:

/** @var Bespoke_Suites_Model_Suites $suite */
$suite = Mage::getModel('bespoke_suites/suites');

// Set whatever fields you have in your table
$suite->setName('foo');
// equivalent:
$suite->setData('name', 'foo');

// Save it
$suite->save();
// Should now have a suites_id set automatically
| improve this answer | |
  • when i try your first code snippet,return in report file a:5:{i:0;s:34:"Resource instance is not available";i:1;s:834:"#0 – Nagendra Nov 9 '15 at 13:54
  • second part of your code returns Fatal error: Call to a member function beginTransaction() – Nagendra Nov 9 '15 at 13:55
  • Records are there in my table – Nagendra Nov 9 '15 at 14:00
1

Please add your model file code, also a bit more information on what your trying to achieve. What are you dumping, and what are you expecting to see?

| improve this answer | |
  • Mage::getModel('module/model'); – Nagendra Nov 9 '15 at 13:26

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.