zendframework / ZFTool

Utility module for maintaining modular Zend Framework 2 applications.
187 stars 101 forks source link

Can't create index.phtml when creating controller #65

Closed ne2da1 closed 11 years ago

ne2da1 commented 11 years ago

When I try create controller with command zf.php create controller I get following errors

Warning: mkdir(): No such file or directory in C:\OpenServer\domains\zf2.local\ZendSkeletonApplication\vendor\zftool\src\ZFTool\Controller\CreateController.php on line 142

Warning: file_put_contents(./module/test/view/test/index/index.phtml): failed to open stream: No such file or directory in C:\OpenServer\domains\zf2.local\ZendSkeletonApplicatio n\vendor\zftool\src\ZFTool\Controller\CreateController.php on line 147 There was an error during controller creation.

I've fixed this by adding following string in moduleAction method in ZFTool\Controller\CreateController class: mkdir("$path/module/$name/view/" . strtolower($name));

mludewig commented 11 years ago

Hey del42rus, but this don't fix the problem, because after adding controller and route to module.config.php, the view stops with an Exception during loading the view phtml script. The strtolower($name) is not the complete working way i think, because the path looking for phtml script is $path/module/$name/view/name-of-the-module (comes here from NameOfTheModule).

best regards mludewig

ne2da1 commented 11 years ago

Hi mludewig, thanks for answer, you are right, the strtolower($name) is not enough to fix problem.

So now I've used CamelCaseToDash filter for building properly path to phtml script. For that it was necessary to change moduleAction and controllerAction in ZFTool\Controller\CreateController class.

In moduleAction I've added following code after all other mkdir functions:

$filter = new CamelCaseToDashFilter(); // include Zend\Filter\Word\CamelCaseToDash class in use section $inflectedModuleName = strtolower($filter->filter($name)); mkdir("$path/module/$name/view/" . $inflectedModuleNameName);

In controllerAction I've changed $dir = $path . "/module/$module/view/" . strtolower($module) . "/" . strtolower($name);

to $filter = new CamelCaseToDashFilter(); $inflectedModuleName = strtolower($filter->filter($module)); $dir = $path . "/module/$module/view/" . strtolower($inflectedModuleName) . "/" . strtolower($name);

It seems to work fine:)

best regards del42rus

weierophinney commented 11 years ago

@del42rus Would you be willing to create a pull request with these changes?

ne2da1 commented 11 years ago

@weierophinney As I can see you have already added recursive flag in mkdir calls. And I've noticed that $viewfolder = strtolower($name).

As @mludewig mentioned above the strtolower($name) is not the complete working way, because the path looking for phtml script is $path/module/$name/view/name-of-the-module (comes here from NameOfTheModule). So we'll have exception during loading the view phtml script.

I've changed code a little bit by adding CamelCaseToDash filter and using it for building properly path to phtml script. Also I've created pull request with these changes