Skip to content

Commit

Permalink
Merge pull request #22 from ashutoshwebkul/dev
Browse files Browse the repository at this point in the history
fixed controller create error and added router name option
  • Loading branch information
Ashutosh Srivastva authored Dec 20, 2019
2 parents 138ceea + 070aef7 commit 1b895bf
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
11 changes: 10 additions & 1 deletion Model/Generate/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,19 @@ private function createRoutesXmlFile($etcDirPath, $data)
$controllerName = $data['name'];
$module = $data['module'];
$area = $data['area'];

$xmlFilePath = $this->getRoutesXmlFilePath($etcDirPath);
if ($this->fileDriver->isExists($xmlFilePath)) {
return true;
}

if (!isset($data['router']) || !$data['router']) {
throw new \RuntimeException(
__('Please provide router name')
);
}
$routeName = $data['router'];

$xmlData = $this->helper->getTemplatesFiles('templates/routes.xml.dist');
$this->helper->saveFile($xmlFilePath, $xmlData);

Expand All @@ -144,7 +153,7 @@ private function createRoutesXmlFile($etcDirPath, $data)
);
}
$routesId = $area == 'adminhtml' ? 'admin' : 'standard';
$routeName = strtolower($this->helper->getClassName($controllerName));
// $routeName = strtolower($this->helper->getClassName($controllerName));
$routerNode = $this->xmlGenerator->addXmlNode(
$routesXml,
'router',
Expand Down
5 changes: 5 additions & 0 deletions Model/Generate/Controller/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function validate($data)

$modulePath = $dir->getDir($module);
$response["path"] = $modulePath;
if (isset($data['router'])) {
$response['router'] = $data['router'];
}

$response["module_path"] = $modulePath;
if ($area == 'frontend') {
$response["path"] = $modulePath.DIRECTORY_SEPARATOR.'Controller';
} else {
Expand Down
7 changes: 7 additions & 0 deletions Model/OptionsPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public function getOptions()
'enter area frontend or adminhtml'
),

new InputOption(
'router',
'r',
InputArgument::OPTIONAL,
'enter router name'
),

//plugin specific
new InputOption(
'plugin',
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you have created the db_schema file for the table in the above command, it wi

- To create controller

``` php bin/magento generate:code Module_Name --type=controller --name=ControllerName --area=frontend|adminhtml --path=RelativeToModuleControolerFolder ```
``` php bin/magento generate:code Module_Name --type=controller --name=ControllerName --area=frontend|adminhtml --path=RelativeToModuleControolerFolder --router=RouteName ```

- To create helper

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webkul/code-generator",
"description": "module lets you generate models, controller, helpers in seconds so that you can focus more on application logic ",
"type": "magento2-module",
"version": "2.0.3",
"version": "2.0.4",
"license": [
"proprietary"
],
Expand Down
9 changes: 1 addition & 8 deletions templates/config.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<?xml version="1.0"?>
<!--
/**
* Webkul Software.
*
* @package Webkul_CodeGenerator
* @author Mahesh Singh
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
</default>
Expand Down
7 changes: 0 additions & 7 deletions templates/routes.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<?xml version="1.0"?>
<!-- /**
/**
* Webkul Software.
*
* @package Webkul_CodeGenerator
* @author Mahesh Singh
*/ -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
</config>
6 changes: 1 addition & 5 deletions templates/shipping/offline_shipping.php.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php
/**
* shipping model
*
* @author Mahesh Singh
*/

namespace %namespace%;

use Magento\Quote\Model\Quote\Address\RateRequest;
Expand Down
7 changes: 1 addition & 6 deletions templates/system.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
</system>
Expand Down

0 comments on commit 1b895bf

Please sign in to comment.