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 Dev Tools issues with path in ini file

Hi All,

Just getting started with Phalcon. Struggled a lot to get the tools up and running but now it works in webstorm and from the terminal. So I initially created a project using this command

phalcon create-project --name test --use-config-ini

It generates the project structure correctly and if I deploy it to the server it works correctly. I want to generate models and now the issue starts because the config ini is generated like this:

[application]

controllersDir = ../app/controllers/

modelsDir = ../app/models/

viewsDir = ../app/views/

pluginsDir = ../app/plugins/

libraryDir = ../app/library/

cacheDir = ../app/cache/

When I run:

phalcon create-model user

it displays it correctly generated the file but is nowhere to be found. If I run:

phalcon -create-controller test

I get the error: Error: Unable to write to '../app/controllers//TestController.php' (Full access has been granted to everyone on the dir).

I noticed when changing the paths by removing the "../" the generation seems to work (eg. modelsDir = app/models/). Which seems strange to me cause I see the same structure working in the tutorial movie.

Does anyone know what might be causing this?



2.9k

Just tested with the same structure but generate a project without the --use-config-ini and then the generators do work properly. Could it be a bug?



2.9k
Accepted
answer
edited Jul '14

I found the solution. Standard the generator places the dir structure is like:

.phalcon

app

config

public

index.php

When I move the .phalcon folder the generator is working properly as it appearantly uses that folder to determine the position. So move the folder

app

--.phalcon

config

public

index.php

Now the generator works fine when I run the generator from the app folder. Seems like a unwanted feature to me ;)



60

did not work for me and sounds kind of ilogic.any other idea that does not imply moving phalcon-generated structure directories?



2.5k

Hi,

I'm on Windows 8 and I've got the same issue with the phalcon-devtools.
When I try to generate a controller (with phalcon controller test), I've got the following error :

Error: Unable to write to '../app/controllers/\TestController.php'

The directories are generate as follow :

  • app
    • cache
    • config
      • config.ini
    • controllers
    • models
    • views
  • public

In my config.ini I've got :

[database]
adapter  = Mysql
host     = localhost
username = root
password = secret
dbname   = test

[application]
controllersDir = ../app/controllers/
modelsDir      = ../app/models/
viewsDir       = ../app/views/
pluginsDir     = ../app/plugins/
libraryDir     = ../app/library/
cacheDir       = ../app/cache/
baseUri        = /project/

[models]
metadata.adapter = "Memory"

I've think the problem comes from the key controllersDir set to ../app/controllers/.
If I execute the phalcon tool in the root of my project, it will use the previous path and it will make something like this :

project/../app/controllers

So I try to put a directory named app at the same level of my project folder and put a sub-folder controllers.
When I run again the phalcon controller test command, it generate a controller inside this new directory.

A quick fix to this is to replace in the following file phalcon-devtools/scripts/Phalcon/Builder/Controller.php the line 85 by :

$controllersDir = 'app/' . $config->application->controllersDir;

So the path become :

project/app/../app/controllers

And the controllers can be generated.

A real fix to this I think will be not to use the working directory as reference, but the position of the config file or folder.