2
<?php


$installer = $this;
echo 'Running This Installation: '.get_class($this)."\n <br /> \n"; 
$installer->startSetup();

$table = $installer->getConnection()
->newTable($installer->getTable('amber_maintenance_mode'))

->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'identity'  => true,
    'unsigned'  => true,
    'nullable'  => false,
    'primary'   => true,
    ), 'Id')

->addColumn('state', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'State'
    )

->addColumn('created_by', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
    'nullable'  => false,
    ), 'Created by'
    )

->addColumn('start_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
    'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
    'nullable' => true,
    'default' => null,
    'comment' => 'Start date'
    ), 'Start Date'
    )

->addColumn('end_date', Varien_Db_Ddl_Table::TYPE_DATE, null, array(
    'type' => Varien_Db_Ddl_Table::TYPE_TIMESTAMP,
    'nullable' => true,
    'default' => null,
    'comment' => 'End date'
    ), 'End Date'
    )

->addColumn('down_reason', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
    'nullable'  => false,
    ), 'Down reason'
    );

$installer->getConnection()->createTable($table);

$installer->endSetup();

Now trying to get data from table ....

$date = Mage::getModel('amber/maintenance_mode')->getCollection();
$date = Mage::getModel('amber_maintenance_mode')->getCollection();
$date = Mage::getModel('amber_maintenance/amber_maintenance_mode')->getCollection();

Nothing works ...... what I'm doing wrong ? Which form is correct if any ?

Here is my config "required section" ;)

        <models>
        <amber_maintenance>
            <class>Amber_Maintenance_Model</class>
            <resourceModel>maintenance_mysql4</resourceModel>
        </amber_maintenance>

        <amber_maintenance_resource>
            <class>Amber_Maintenance_Model_Resource</class>
                <entities>
                    <mode>
                        <table>amber_maintenance_mode</table>
                    </mode>
                </entities>

        </amber_maintenance_resource>   
    </models>

    <resources>
        <maintenance_setup>
            <setup>
                <module>Amber_Maintenance</module>
                <class>Mage_Core_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </maintenance_setup>
        <maintenance_write>
            <connection>
                <use>core_write</use>
            </connection>
        </maintenance_write>
        <maintenance_read>
            <connection>
                <use>core_read</use>
            </connection>
        </maintenance_read>
    </resources>
3
  • please add your config.xml and model file code Commented Feb 4, 2017 at 17:21
  • $date = Mage::getModel('amber_maintenance/mode')->getCollection(); should get you your data. Commented Feb 4, 2017 at 17:36
  • That's what I expected, but it won't do anything.
    – Rob D. A.
    Commented Feb 4, 2017 at 17:41

2 Answers 2

5

Update your models tag like below,

<models>
    <amber_maintenance>
        <class>Amber_Maintenance_Model</class>
        <resourceModel>amber_maintenance_resource</resourceModel>
    </amber_maintenance>
    <amber_maintenance_resource>
        <class>Amber_Maintenance_Model_Resource</class>
            <entities>
                <mode>
                    <table>amber_maintenance_mode</table>
                </mode>
            </entities>
    </amber_maintenance_resource>   
</models>

Now use,

Mage::getModel('amber_maintenance/mode')->getCollection();

Or

$collection = Mage::getResourceModel('amber_maintenance/mode_collection');
9
  • Updated ..... still nothing, on screen all I can see is "bool(false)" in left top corner just above header ;)
    – Rob D. A.
    Commented Feb 4, 2017 at 18:20
  • Can you confirm if you have data in your table, also check if you can load a single object with id by using, Mage::getModel('amber_maintenance/mode')->load(ID_OF_RECORD) Commented Feb 4, 2017 at 18:40
  • Nope, nothig. $single = Mage::getModel('amber_maintenance/mode')->load(1); Blank screen :)
    – Rob D. A.
    Commented Feb 4, 2017 at 18:45
  • Can you confirm with this link if you are not missing any file or code. pixafy.com/blog/2013/04/creating-a-magento-custom-model Commented Feb 4, 2017 at 18:48
  • Yes I can confirm, everything works except it wont fetch any data from table using magento methods. If add a mysql query I can pull data from any table, but to build grid with data I must be able to do it using Magento collection ....bla bla bla ;)
    – Rob D. A.
    Commented Feb 4, 2017 at 18:54
3

I think one of the problem is that you have a node

<resourceModel>maintenance_mysql4</resourceModel>

and then you are using

    <amber_maintenance_resource>
        <class>Amber_Maintenance_Model_Resource</class>
            <entities>
                <mode>
                    <table>amber_maintenance_mode</table>
                </mode>
            </entities>
    </amber_maintenance_resource>  

With your notation, you should write :

    <resourceModel>amber_maintenance_resource</resourceModel> 
4
  • Good spot ;) Checking ;)
    – Rob D. A.
    Commented Feb 4, 2017 at 17:57
  • Still nothing but .... at least no blank screen :)
    – Rob D. A.
    Commented Feb 4, 2017 at 18:12
  • $collection2 = Mage::getModel('amber_maintenance/mode')->getCollection();
    – Rob D. A.
    Commented Feb 4, 2017 at 18:16
  • this method causing "blank screen"
    – Rob D. A.
    Commented Feb 4, 2017 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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