The essence of the task is to initialize the database, more precisely, the ds_news_entities table. I work with magento for the first time, that's why there was a problem ( Full Release - ver 1.9.2.4 version Full Release - ver 1.9.2.4 ).

In the app/code/local/TestModule directory app/code/local/TestModule create the directory of my News module

Immediately in the config app/code/local/TestModule/News/etc/config.xml set the settings:

 <?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <TestModule_News> <version>0.0.1</version> </TestModule_News> </modules> </config> 

The next step is to create a config in app/etc/modules/TestModule_News.xml :

 <?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <TestModule_News> <active>true</active> <codePool>local</codePool> </TestModule_News> </modules> </config> 

Then in the app/code/local/TestModule/News/sql testmodulenews_setup create the testmodulenews_setup subdirectory and install-0.0.1.php installation file in it:

 $installer = $this; $installer->startSetup(); $installer->run("CREATE TABLE ds_news_entities ( `news_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `content` TEXT NOT NULL, `created` DATETIME, PRIMARY KEY (`news_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $installer->endSetup(); 

After this, I edit the previously created configuration file app/etc/modules/TestModule_News.xml:

 <?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <TestModule_News> <active>true</active> <codePool>local</codePool> </TestModule_News> </modules> <global> <resources> <testmodulenews_setup> <setup> <module>TestModule_News</module> </setup> </testmodulenews_setup> </resources> </global> </config> 

According to the idea, after updating the page, an entry should be created in the core_resource table corresponding to the name of the table being created.

But after reloading the page, an error occurs:

0 /home/vitaliy/hosts/magento.dev/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement-> execute (Array) # 1

/home/vitaliy/hosts/magento.dev/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo -> _ execute (Array) # 2 /home/vitaliy/hosts/magento.dev/app/ code / core / Zend / Db / Statement.php (291): Varien_Db_Statement_Pdo_Mysql -> _ execute (Array) # 3 /home/vitaliy/hosts/magento.dev/lib/Zend/Db/Adapter/Abstract.php (480): Zend_Db_Statement-> execute (Array) # 4 /home/vitaliy/hosts/magento.dev/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract-> query ('CREATE TABLE ds ...' , Array) # 5 /home/vitaliy/hosts/magento.dev/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract-> query ('CREATE TABLE ds ...', Array) # 6 /home/vitaliy/hosts/magento.dev/lib/Varien/Db/Adapter/Pdo/Mysql.php(423): Varien_Db_Adapter_Pdo_Mysql-> query ('CREATE TABLE ds ...') # 7 / home / vitaliy / hosts / magento.dev / lib / Varien / Db / Adapter / Pdo / Mysql.php (693): Varien_Db_Adapter_Pdo_Mysql-> raw_query ('CREATE TABLE ds ...') # 8 /home/vitaliy/hosts/magento.dev/ lib / Varien / Db / Adapter / Pdo / Mysql.php (675): Varien_Db_Adapter_Pdo_M ysql-> multi_query ('CREATE TABLE ds ...') # 9 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/Resource/Setup.php(932): Varien_Db_Adapter_Pdo_Mysql- > multiQuery ('CREATE TABLE ds ...') # 10 /home/vitaliy/hosts/magento.dev/app/code/local/TestModule/News/sql/testmodulenews_setup/install-0.0.1.php(17): Mage_Core_Model_Resource_Setup-> run ('CREATE TABLE ds ...') # 11 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/Resource/Setup.php(66): include ( '/ home / vitaliy / h ...') # 12 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/Resource/Setup.php(421): Mage_Core_Model_Resource_Setup -> _ modifyResourceDb ('install', '', '0.0.1') # 13 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/Resource/Setup.php(327): Mage_Core_Model_Resource_Setup- > _installResourceDb ('0.0.1') # 14 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Core_Model_Resource_Setup-> applyUpdates () # 15 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/ Model / App.php (428): Mage_Core_Model_Resource_Setup :: applyAllUpdates () # 16 /home/vitaliy/hosts/magento.dev/app/code/core/Mage/Core/Model/App.php (3535): Mage_Core_Model_App _initModules () # 17 /home/vitaliy/hosts/magento.dev/app/Mage.php(683): ​​Mage_Core_Model_App-> run (Array) # 18 /home/vitaliy/hosts/magento.dev/index.php(83 ): Mage :: run ('', 'store')

19 {main} errord

What am I wrong? Or doing something wrong?

Please hints (

    1 answer 1

    You must create a resource model, i.e. in configs to register

      <your_module> <class>You_Module_Model</class> <resourceModel>your_module_resource</resourceModel> </your_module> 

    further we configure resource model

      <your_module_resource> <class>Your_Module_Model_Resource</class> <entities> <yourtable> <table>your_table</table> </yourtable> </entities> </your_module_resource> 

    Further in a config we register resource setup

      <resources> <your_module_setup> <setup> <module>Your_Module</module> </setup> </your_module_setup> </resources> 

    your_module_setup note that your_module_setup is the name of the sql subdirectory directory.

    further we create our model

     class Your_Module_Model_Model extends Mage_Core_Model_Abstract { protected $_dataLayer = null; function _construct() { $this->_init('your_module/yourtable'); } } 

    Now create the Resource directory in the Model directory. and there is a model resource file

     class Your_Module_Model_Resource_Model extends Mage_Core_Model_Resource_Db_Abstract { /** * Resource initialization */ protected function _construct() { $this->_init('your_module/yourtable','entity_id'); } } 

    and the last stroke is to create a Collection , in the Resource directory we create a subdirectory with the name of the Model resource file in our case, a rather bad name, you will excuse me. And in this directory we create the file Collection.php

     class Your_Model_Model_Resource_Model_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * init collection */ protected function _construct() { $this->_init('your_module/yourtable'); } } 

    I specifically did not give a full working example and the name of the ones you gave. Sadly, to work with magento, you need to know English at least at a technical level. This article http://inchoo.net/magento/magento-install-install-upgrade-data-and-data-upgrade-scripts/ and my answer will help you with your task. Good luck, and if there are any difficulties with the Magenta, please write to ru.stackoverflow.com I will try to respond promptly. Since magento is pretty hard to understand architecture, it is better to ask a question and get an answer than to invent a functional that already exists. Good luck to you!

    • thank you very much) It helped me a lot! - Maybe_V 7:02