We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon devtools all-model generation fail with the path

I was unable to rebuild my model after upgrading from phalcon 1.3.2 to 1.3.4 and the latest (master) devtool

This is the error I received

C:\wamp\www\myproject\application\myapp>phalcon all-models --relations --fk --validations --get-set --doc --force --namespace=Myapp\Models --extends=\Myapp\Library\ModelBase

Phalcon DevTools (1.3.4)
  Error: Unable to write to '.\public/C:\wamp\www\myproject\application\myapp\app\config/../../app/models\Admin.php'

I figured out it was going into a condition that I didn't need (i think) from the phalcon-dev-tools-master/scripts/Phalcon/commands/Builtin/AllModels.php line #86

       if (file_exists($path.'public')) {
            $modelsDir = 'public/'.$config->application->modelsDir;
        } else {
            $modelsDir = $config->application->modelsDir;
        }

After commenting the "public" part it resolved my issue:

        //            if (file_exists($path.'public')) {
        //                $modelsDir = 'public/'.$config->application->modelsDir;
        //            } else {
                          $modelsDir = $config->application->modelsDir;
        //            }

I also tried to specify the path with the --directory=s parameter but it did even worst

  Error: Unable to write to 'C:\wamp\www\myproject\application\myapp/\public/C:\wamp\www\myproject\application\myapp\app\config/../../app/models\Admin.php'

Am I missing something?

Thanks !



2.5k

Hi,

I've got the a similar problem with the controller (see this discussion).

For me, there is a confusion with the path (relative to the config.ini) but I didn't had time to check that.

The --directory=s parameter seams to determine the directory of the project and not the target path for the generated files, as I can see on the files inside the folder phalcon-devtools\scripts\Phalcon\Builder.

Hi,

I've got the a similar problem with the controller (see this discussion).

For me, there is a confusion with the path (relative to the config.ini) but I didn't had time to check that.

The --directory=s parameter seams to determine the directory of the project and not the target path for the generated files, as I can see on the files inside the folder phalcon-devtools\scripts\Phalcon\Builder.

Yes, but even if I specify the "--directory=s" it just adds a random "\public" in the middle of the path, and it keeps using the absolute path instead of the relative after. Take a look "Error: Unable to write to 'C:\wamp\www\myproject\application\myapp/\public/C:\wamp\www\myproject\application\myapp\app\config/../../app/models\Admin.php'"

Hey, maybe i'm completely wrong but It seems to me to be a permission problem. Are you sure that the folder exist and that you have the right to write in it ?



69
edited Feb '15

Simillar problem here when running "phalcon all-models --relations", not sure which directory need to be set, eventhough I have recursively made whole app directory structure to writeable and tried add --directory, but have no luck, "Error: Unable to write" still occur:

Phalcon DevTools (1.3.4) Error: Unable to write to '/home/phalcon/public_html/blog//public//home/phalcon/public_html/blog/app/config/../../app/models/Categories.php'

Any idea?

It is not a permission problem.

Hey, maybe i'm completely wrong but It seems to me to be a permission problem. Are you sure that the folder exist and that you have the right to write in it ?



3.8k
Accepted
answer

Yup, don't specify any --directory parameter, make sure to run the command inside your app (at root level) in your case under /home/phalcon/publichtml/blog/ after commenting the lines that fail.

File name: \phalcon-devtools-master\scripts\Phalcon\Commands\Builtin\AllModels.php file Line #86

//if (file_exists($path.'public')) {
//    $modelsDir = 'public/'.$config->application->modelsDir;
//} else {
    $modelsDir = $config->application->modelsDir;
//}

If you don't want or can't edit the file as suggested below, you can try to temporary rename your "public" folder inside your app so phalcon doesn't change the models directory.

I don't know why but phalcon is looking if the "public" folder exists inside your app and it just thinks the models directory is inside that folder. If the public folder doesn't exists then it just works as it should. But honestly who the hell in this world puts the model directory inside the public folder? This is just completely wrong.

Simillar problem here when running "phalcon all-models --relations", not sure which directory need to be set, eventhough I have recursively made whole app directory structure to writeable and tried add --directory, but have no luck, "Error: Unable to write" still occur:

Phalcon DevTools (1.3.4) Error: Unable to write to '/home/phalcon/public_html/blog//public//home/phalcon/public_html/blog/app/config/../../app/models/Categories.php'

Any idea?

model path is wrong with both "pahlcon model " and "phalcon all model" . I modified the script of dev tools:

https://coding.net/bati/phalcon-devtools-bati_v1.git

edited Mar '15

Had a similar issue the other day I posted my work around here : https://stackoverflow.com/q/29013449/2221407

Find

\devtools\scripts\Phalcon\Builder\

And open Components.php

Inside this file find the line:

foreach (array('/app/config/', 'config/') as $configPath) {

This line needs to be either:

(array('/../app/config/'  <- For Scaffolding Generator to work.

or

(array('../app/config/' <- For Models Generator to work.

I can't for the life of me work why, and it's far from ideal trying to remember to do it every time you need to use the tools, but it works.



1.7k

Had the same problem days ago,

I added some condition to the if statement that selects the right path and did a pull request https://github.com/phalcon/phalcon-devtools/pull/317

It worked for me, Hope helps someone too!