Zend Framework

zf create controller fails on Windows with ZF 1.9

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.9.0
  • Fix Version/s: 1.9.1
  • Component/s: Zend_Tool
  • Labels:
    None

Description

On Windows, using trunk or release-1.9 branch:

>zf create project mytest
>cd mytest
>zf create controller foo

Generates this error:

An Error Has Occurred
 A project profile was not found.

Zend Framework Command Line Console Tool v1.9.0a1
Details for action "Create" and provider "Controller"
  Controller
    zf create controller name index-action-included[=1] module

Activity

Hide
Rob Allen added a comment -

The problem is on line 126 of Zend/Tool/Project/Provider/Abstract.php:

$projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);

On Windows, this creates a $projectDirectoryAssembled of \C:\www\mytest for me!

Clearly the leading \ is wrong for Windows. Suggested patch:

Index: Zend/Tool/Project/Provider/Abstract.php
===================================================================
--- Zend/Tool/Project/Provider/Abstract.php	(revision 17369)
+++ Zend/Tool/Project/Provider/Abstract.php	(working copy)
@@ -123,7 +123,11 @@
         
         $parentDirectoriesArray = explode(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
         while ($parentDirectoriesArray) {
-            $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            if(substr(PHP_OS, 0, 3) != 'WIN') {
+                // prepend the DIRECTORY_SEPARATOR only if not on Windows
+                $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
+            }
             
             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
             if ($profile->isLoadableFromFile()) {
Show
Rob Allen added a comment - The problem is on line 126 of Zend/Tool/Project/Provider/Abstract.php: $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray); On Windows, this creates a $projectDirectoryAssembled of \C:\www\mytest for me! Clearly the leading \ is wrong for Windows. Suggested patch:
Index: Zend/Tool/Project/Provider/Abstract.php
===================================================================
--- Zend/Tool/Project/Provider/Abstract.php	(revision 17369)
+++ Zend/Tool/Project/Provider/Abstract.php	(working copy)
@@ -123,7 +123,11 @@
         
         $parentDirectoriesArray = explode(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
         while ($parentDirectoriesArray) {
-            $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            if(substr(PHP_OS, 0, 3) != 'WIN') {
+                // prepend the DIRECTORY_SEPARATOR only if not on Windows
+                $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
+            }
             
             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
             if ($profile->isLoadableFromFile()) {
Hide
Rob Allen added a comment -

Alternative patch from ZF-7338:

Index: Abstract.php
===================================================================
--- Abstract.php	(revision 16969)
+++ Abstract.php	(working copy)
@@ -120,11 +120,14 @@
         }
 
         $profile = new Zend_Tool_Project_Profile();
-        
-        $parentDirectoriesArray = split(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
+        $parentDirectoriesArray = split(preg_quote(DIRECTORY_SEPARATOR), ltrim($projectDirectory, DIRECTORY_SEPARATOR));
         while ($parentDirectoriesArray) {
-            $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
             
+            if (DIRECTORY_SEPARATOR != "\\") { // Seems to be a windows path
+              $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
+            }
+            
             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
             if ($profile->isLoadableFromFile()) {
                 chdir($projectDirectoryAssembled);
Show
Rob Allen added a comment - Alternative patch from ZF-7338:
Index: Abstract.php
===================================================================
--- Abstract.php	(revision 16969)
+++ Abstract.php	(working copy)
@@ -120,11 +120,14 @@
         }
 
         $profile = new Zend_Tool_Project_Profile();
-        
-        $parentDirectoriesArray = split(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
+        $parentDirectoriesArray = split(preg_quote(DIRECTORY_SEPARATOR), ltrim($projectDirectory, DIRECTORY_SEPARATOR));
         while ($parentDirectoriesArray) {
-            $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
             
+            if (DIRECTORY_SEPARATOR != "\\") { // Seems to be a windows path
+              $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
+            }
+            
             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
             if ($profile->isLoadableFromFile()) {
                 chdir($projectDirectoryAssembled);
Hide
Ralph Schindler added a comment -

Fixed in r17521 in trunk

Show
Ralph Schindler added a comment - Fixed in r17521 in trunk
Hide
françois BOUKHALFA added a comment -

Hi sorry but i've just do a fresh checkout (r17563) and tried zf.bat on windows XP and it didn't worked for me :

i had to edit Abstract.php on line 126 like this to make it work

$projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);

regards

Show
françois BOUKHALFA added a comment - Hi sorry but i've just do a fresh checkout (r17563) and tried zf.bat on windows XP and it didn't worked for me : i had to edit Abstract.php on line 126 like this to make it work $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray); regards
Hide
Ralph Schindler added a comment -

Updating Fix Information

Show
Ralph Schindler added a comment - Updating Fix Information
Hide
Rob Kunkle added a comment -

I just checked out 1.9.1 from subversion, and this bug is still there. The second fix above works for me, but I do get the following (php 5.3.0) due to the use of the split()

Deprecated: Function split() is deprecated in C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Tool\Project\Provider\Abstract.php on line 124

thanks!

Show
Rob Kunkle added a comment - I just checked out 1.9.1 from subversion, and this bug is still there. The second fix above works for me, but I do get the following (php 5.3.0) due to the use of the split() Deprecated: Function split() is deprecated in C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Tool\Project\Provider\Abstract.php on line 124 thanks!
Hide
Sebastian Schurr added a comment -

Same here. Just checked the 1.9.1 SVN. In abstract.php (Revision 17521) it should be fixed but still doesn't work for me.

This worked for me:

if (DIRECTORY_SEPARATOR == "\\") {
    $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
    } else {
    $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
}

inserted at line 127.

thanks!

Show
Sebastian Schurr added a comment - Same here. Just checked the 1.9.1 SVN. In abstract.php (Revision 17521) it should be fixed but still doesn't work for me. This worked for me:
if (DIRECTORY_SEPARATOR == "\\") {
    $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
    } else {
    $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
}
inserted at line 127. thanks!
Hide
Murad Jamal added a comment -

guys i can't find the line:
$projectDirectoryAssembled .... etc ...
in
C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Tool\Project\Provider\Abstract.php
and also i can't find the line :
$parentDirectoriesArray ... etc ..
in the same file ...

where can i find these lines to fix them ? im stuck now ...

Show
Murad Jamal added a comment - guys i can't find the line: $projectDirectoryAssembled .... etc ... in C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Tool\Project\Provider\Abstract.php and also i can't find the line : $parentDirectoriesArray ... etc .. in the same file ... where can i find these lines to fix them ? im stuck now ...
Hide
Murad Jamal added a comment -

i downloaded latest version of zend framework, and i find those lines in abstract.php
i tried both solutions but didn't work ...
i still see the same message
a project profile was not found ...
why ???

anyone help me please ...

Show
Murad Jamal added a comment - i downloaded latest version of zend framework, and i find those lines in abstract.php i tried both solutions but didn't work ... i still see the same message a project profile was not found ... why ??? anyone help me please ...
Hide
Enkhbilguun Erdenetsogt added a comment -

I'm working on ZF1.9.1 and Zend Studio 7.0. Both ZF 1.9.1 and ZS 7.0's Zend_Tool is not working properly. I cannot create neither controller nor action. Therefore ZS 7.0's code autocompletion has become maybe 5 times slower and has too many bugs like alpha or beta build.

Show
Enkhbilguun Erdenetsogt added a comment - I'm working on ZF1.9.1 and Zend Studio 7.0. Both ZF 1.9.1 and ZS 7.0's Zend_Tool is not working properly. I cannot create neither controller nor action. Therefore ZS 7.0's code autocompletion has become maybe 5 times slower and has too many bugs like alpha or beta build.
Hide
Murad Jamal added a comment -

here's the error message i get:

C:\Users\Administrator\Zend\workspaces\DefaultWorkspace7>"C:/Program Files/Zend/Zend Studio - 7.0.0/plugins/org.zend.php.framework.resource_7.0.0.v20090531-1639/resources/ZendFramework-1/bin//zf.bat" create action edit index
An Error Has Occurred
A project profile was not found.

Zend Framework Command Line Console Tool v1.9.1
Details for action "Create" and provider "Action"
Action
zf create action name controller-name[=index] view-included[=1] module

what the hell is this ? i tried all the solutions you wrote, but without any effect ...

Show
Murad Jamal added a comment - here's the error message i get: C:\Users\Administrator\Zend\workspaces\DefaultWorkspace7>"C:/Program Files/Zend/Zend Studio - 7.0.0/plugins/org.zend.php.framework.resource_7.0.0.v20090531-1639/resources/ZendFramework-1/bin//zf.bat" create action edit index An Error Has Occurred A project profile was not found. Zend Framework Command Line Console Tool v1.9.1 Details for action "Create" and provider "Action" Action zf create action name controller-name[=index] view-included[=1] module what the hell is this ? i tried all the solutions you wrote, but without any effect ...
Hide
Rob Kunkle added a comment -

Hi Murad -

The problem is that you need to be in the project directory when you run zf create action...otherwise zf can't find the project profile

cd c:\apache\htdocs\

zf create project myproject

cd C:\apache\htdocs\myproject\

then

zf create controller blah blah


Is there any way to reopen this bug to get the source code fixed?

Show
Rob Kunkle added a comment - Hi Murad - The problem is that you need to be in the project directory when you run zf create action...otherwise zf can't find the project profile cd c:\apache\htdocs\ zf create project myproject cd C:\apache\htdocs\myproject\ then zf create controller blah blah
Is there any way to reopen this bug to get the source code fixed?
Hide
Murad Jamal added a comment -

Hi Rob,
i tried exactly what you told me without any benefit
from inside my zend studio 7, i opened Zend Tool, typed cd C:\Program Files\Zend\Apache2\htdocs\project1
but it gives me the following error:

cd C:\Program Files\Zend\Apache2\htdocs\project1
Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project.
Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project.
ok (took 0:00.000)
Error: Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project.

although there was an existing zend framework project in that directory ...
this is so weird ?
anyone can help me please ?

Show
Murad Jamal added a comment - Hi Rob, i tried exactly what you told me without any benefit from inside my zend studio 7, i opened Zend Tool, typed cd C:\Program Files\Zend\Apache2\htdocs\project1 but it gives me the following error: cd C:\Program Files\Zend\Apache2\htdocs\project1 Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project. Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project. ok (took 0:00.000) Error: Error resolving path: cd C:\Program Files\Zend\Apache2\htdocs\project1, specify an existing ZF project. although there was an existing zend framework project in that directory ... this is so weird ? anyone can help me please ?
Hide
Carsten Schmitz added a comment -

I have with ZF 1.9.1 the same problem like in the description at the top.

The following code doesn't work:
zf create project test => OK

  • cd test
  • zf create controller guestbook => Error!

With ZF 1.8.4 Patch 1 the code works.

Show
Carsten Schmitz added a comment - I have with ZF 1.9.1 the same problem like in the description at the top. The following code doesn't work: zf create project test => OK
  • cd test
  • zf create controller guestbook => Error!
With ZF 1.8.4 Patch 1 the code works.
Hide
Ralph Schindler added a comment -

Please see ZF-7607, a fix as been put in place in trunk and release 1.9 branch that fixes this issue.

Show
Ralph Schindler added a comment - Please see ZF-7607, a fix as been put in place in trunk and release 1.9 branch that fixes this issue.

People

Vote (1)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: