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>
.....
4
  • try to dump $model->getData() Commented Nov 9, 2015 at 13:50
  • @razbakov Fatal error: Call to a member function getData() Commented Nov 9, 2015 at 13:58
  • $model = Mage::getModel('bespoke_suites/suites')->load(1); print_r($model->getData()); Commented Nov 9, 2015 at 14:07
  • @razbakov resource instance is not available means what in this case? Commented Nov 10, 2015 at 4:55

1 Answer 1

4

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
3
  • 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 Commented Nov 9, 2015 at 13:54
  • second part of your code returns Fatal error: Call to a member function beginTransaction() Commented Nov 9, 2015 at 13:55
  • Records are there in my table Commented Nov 9, 2015 at 14:00

Your Answer

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.