Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

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

Closed
ne2da1 opened this issue Aug 24, 2013 · 4 comments
Closed

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

ne2da1 opened this issue Aug 24, 2013 · 4 comments

Comments

@ne2da1
Copy link
Contributor

ne2da1 commented Aug 24, 2013

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
Copy link

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
Copy link
Contributor Author

ne2da1 commented Aug 28, 2013

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
Copy link
Member

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

@ne2da1
Copy link
Contributor Author

ne2da1 commented Sep 6, 2013

@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

weierophinney added a commit that referenced this issue Sep 6, 2013
[#65] Use CamelCaseToDash filter for building properly path to phtml script
weierophinney added a commit that referenced this issue Sep 6, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants