Trying to install sample module in Magento 2 from this. Below is the module structure app/code/NameSpace/Module/
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Magentostudy_News" setup_version="0.0.1" schema_version="0.0.1"/>
</config>
composer.json
{
"name": "magentostudy/module-news",
"description": "N/A",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/module-store": "100.0.0",
"magento/module-email": "100.0.0",
"magento/module-ui": "100.0.0",
"magento/framework": "100.0.0"
},
"type": "magento2-module",
"version": "0.0.1",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [ "registration.php" ],
"psr-4": {
"Magentostudy\\News\\": ""
}
}
}
Registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magentostudy_News',
__DIR__
);
Executing below command to enable module
php ./bin/magento module:enable Magentostudy_News
It says there are no commands defined in the "module" namespace.
Also on frontend it throws below exception. I am using composer but not github.
Fatal error: Uncaught exception 'Magento\Framework\Exception\LocalizedException' with message 'Source class "\Magento\Framework\Module\Updater\Setup" for "Magento\Framework\Module\Updater\SetupFactory" generation does not exist.'
CODE EDIT
Added Setup
folder with file InstallSchema.php
which includes below code
<?php
/**
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
*/
/* @var $installer \Magento\Setup\Module\SetupModule */
namespace Magentostudy\News\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
$installer = $this;
$installer->startSetup();
/**
* Creating table magentostudy_news
*/
$table = $installer->getConnection()->newTable(
$installer->getTable('magentostudy_news')
)->addColumn(
'news_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Entity Id'
)->addColumn(
'title',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['nullable' => true],
'News Title'
)->addColumn(
'author',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['nullable' => true,'default' => null],
'Author'
)->addColumn(
'content',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'2M',
['nullable' => true,'default' => null],
'Content'
)->addColumn(
'image',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
null,
['nullable' => true,'default' => null],
'News image media path'
)->addColumn(
'created_at',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
null,
['nullable' => false],
'Created At'
)->addColumn(
'published_at',
\Magento\Framework\DB\Ddl\Table::TYPE_DATE,
null,
['nullable' => true,'default' => null],
'World publish date'
)->addIndex(
$installer->getIdxName(
'magentostudy_news',
['published_at'],
\Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX
),
['published_at'],
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX]
)->setComment(
'News item'
);
$installer->getConnection()->createTable($table);
$installer->endSetup();
- What is the correct way to install Magento 2 modules ?
- Any crucial step I missed ?
Reference URL : http://mageinferno.com/blog/setting-up-magento-2-module-right-way-composer-packagist