<?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>
2 Answers 2
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');
answered Feb 4, 2017 at 17:58
Jaimin Sutariya
11.2k5 gold badges38 silver badges72 bronze badges
-
Updated ..... still nothing, on screen all I can see is "bool(false)" in left top corner just above header ;)Rob D. A.– Rob D. A.2017年02月04日 18:20:18 +00:00Commented 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)Jaimin Sutariya– Jaimin Sutariya2017年02月04日 18:40:21 +00:00Commented Feb 4, 2017 at 18:40 -
Nope, nothig. $single = Mage::getModel('amber_maintenance/mode')->load(1); Blank screen :)Rob D. A.– Rob D. A.2017年02月04日 18:45:00 +00:00Commented 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-modelJaimin Sutariya– Jaimin Sutariya2017年02月04日 18:48:53 +00:00Commented 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.– Rob D. A.2017年02月04日 18:54:58 +00:00Commented Feb 4, 2017 at 18:54
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>
answered Feb 4, 2017 at 17:55
Julien Loizelet
1,1988 silver badges16 bronze badges
-
Good spot ;) Checking ;)Rob D. A.– Rob D. A.2017年02月04日 17:57:51 +00:00Commented Feb 4, 2017 at 17:57
-
Still nothing but .... at least no blank screen :)Rob D. A.– Rob D. A.2017年02月04日 18:12:43 +00:00Commented Feb 4, 2017 at 18:12
-
$collection2 = Mage::getModel('amber_maintenance/mode')->getCollection();Rob D. A.– Rob D. A.2017年02月04日 18:16:10 +00:00Commented Feb 4, 2017 at 18:16
-
this method causing "blank screen"Rob D. A.– Rob D. A.2017年02月04日 18:16:29 +00:00Commented Feb 4, 2017 at 18:16
default
config.xmland model file code$date = Mage::getModel('amber_maintenance/mode')->getCollection();should get you your data.