Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder doesn't know where is the models directory #222

Closed
scrnjakovic opened this issue Jun 6, 2014 · 14 comments
Closed

Builder doesn't know where is the models directory #222

scrnjakovic opened this issue Jun 6, 2014 · 14 comments
Assignees

Comments

@scrnjakovic
Copy link

I get this error trying to generate models, although I can generate controllers O.o
That error I get when I try to generate ALL models, and when I try to generate only one, I get Database configuration cannot be loaded from your config file
v 1.3.1
btw I'm using config as php, generated from devtools.

EDIT: Okay, there has to be something wrong with permissions and users. All the files created by webtools are owned by O.o Any thoughts about how to handle this ?

@scrnjakovic
Copy link
Author

Devtools doesn't work either. Throws builder doesn't know where is the models directory...

@dannyweldon
Copy link

I had this problem when I created a project with webtools, but it was okay without webtools. It affected both webtools and the phalcon cli. The modelsDir location in app/config/config.php file was correct in both instances. I could avoid the error in the project directory by specifying the directory with $PWD or even just "." on the phalcon cli. So it seems to be an issue with finding the config directory when webtools has been installed.

@dannyweldon
Copy link

I just uninstalled webtools and then I could create the models again with phalcon cli:

phalcon webtools --action=disable
phalcon all-models

@valVk
Copy link

valVk commented Aug 14, 2014

There is wrong regular expression in ~/phalcon-devtools/scripts/Phalcon/Builder/Component.php

/**
     * Tries to find the current configuration in the application
     *
     * @param $path
     *
     * @return mixed|\Phalcon\Config\Adapter\Ini
     * @throws \Phalcon\Builder\BuilderException
     */
    protected function _getConfig($path)
    {
        foreach (array('app/config/', 'config/') as $configPath) {
            if (file_exists($path . $configPath . "config.ini")) {
                return new \Phalcon\Config\Adapter\Ini($path . $configPath . "/config.ini");
            } else {
                if (file_exists($path . $configPath. "/config.php")) {
                    $config = include($path . $configPath . "/config.php");

                    return $config;
                }
            }
        }

        $directory = new \RecursiveDirectoryIterator('.');
        $iterator = new \RecursiveIteratorIterator($directory);
        foreach ($iterator as $f) {
            //if (preg_match('/config\.php$/i', $f->getPathName())) { - Wrong expression
            if (preg_match('/\/config\.php$/i', $f->getPathName())) {
                $config = include $f->getPathName();

                return $config;
            } else {
                if (preg_match('/\/config\.ini$/i', $f->getPathName())) {
                    return new \Phalcon\Config\Adapter\Ini($f->getPathName());
                }
            }
        }
        throw new BuilderException('Builder can\'t locate the configuration file');
    }

If do not fix that, than webtools.config.php file will match as config file.
I think rule for config.ini should be changed as well.
And maybe is better change regex delimeter from / to something else for example ~, and do not make additional escaping for slashes

@javagrails
Copy link

I download [ Phalcon 1.3.4 - Windows x86 for PHP 5.6.0 (VC11) ] this and download dev tools from [ https://github.com/phalcon/phalcon-devtools ] and create project with webdevtools and configure ip but my web interface of dev tools not working... give different errors like [database][adapter] ... and so on.... and some menu missing in web interface [ Configuration tab ] shown in video.... so what's the problem how can i fix it... could u please help me. I use php 5.6.3 and there is no config.ini file in app but DB config found it config.php

@evgensoft2015
Copy link

for create ini-file use command create project:
phalcon create-project PROJECT_NAME --use-config-ini --enable-webtools

@valVk
Copy link

valVk commented Feb 25, 2015

small changes

/**
     * Tries to find the current configuration in the application
     *
     * @param $path
     *
     * @return mixed|\Phalcon\Config\Adapter\Ini
     * @throws \Phalcon\Builder\BuilderException
     */
    protected function _getConfig($path)
    {
        foreach (array('app/config/', 'config/') as $configPath) {
            if (file_exists($path . $configPath . "config.ini")) {
                return new \Phalcon\Config\Adapter\Ini($path . $configPath . "/config.ini");
            } else {
                if (file_exists($path . $configPath. "/config.php")) {
                    $config = include($path . $configPath . "/config.php");

                    return $config;
                }
            }
        }

        $directory = new \RecursiveDirectoryIterator('..');
        $iterator = new \RecursiveIteratorIterator($directory);
        foreach ($iterator as $f) {
            if (preg_match('/\/config\.php$/i', $f->getPathName())) {
                $config = include $f->getPathName();

                return $config;
            } else {
                if (preg_match('/\/config\.ini$/i', $f->getPathName())) {
                    return new \Phalcon\Config\Adapter\Ini($f->getPathName());
                }
            }
        }
        throw new BuilderException('Builder can\'t locate the configuration file');
    }

@javagrails
Copy link

Builder can't locate the configuration file -- i can not identify it... why and where it comes from when i try to create controllers or model... above 2 suggestion i applied but still this problem going on

@nightowl77
Copy link

Hi Guys

Just ran into this myself.

This problem is not with Component.php (it would seem like it, because it is always returning 1). I added a debug message to check what Component was doing. This is the result

Phalcon DevTools (1.3.4)

Line 65 of Component.php is now checking for.app/config//config.php
Line 65 of Component.php is now checking for.config//config.php

  Error: Builder doesn't knows where is the models directory  

As you can see from this, it is checking for the wrong directory. It gets that from $path, which is set in Models.php

The wrong $path is set in Models.php on line 240

It looks like this

     $path = '';
        if (isset($this->_options['directory'])) {
            if ($this->_options['directory']) {
                $path = $this->_options['directory'] . '/';
            }
        } else {
            $path = '.';
        }

There is a missing slash in the last "else" block. When you add the slash everything works

 if (!$this->_options['name']) {
            throw new BuilderException("You must specify the table name");
        }

        $path = '';
        if (isset($this->_options['directory'])) {
            if ($this->_options['directory']) {
                $path = $this->_options['directory'] . '/';
            }
        } else {
            $path = './';
        }

New debug after slash was added:

Phalcon DevTools (1.3.4)

Line 65 of Component.php is now checking for./app/config//config.php

  Success: Model "users" was successfully created.  

@valVk
Copy link

valVk commented Apr 10, 2015

LOL.
Is that bug will be fixed or not? )

@javagrails
Copy link

none of the above solution works properly sad :(

@sergeyklay
Copy link
Member

I'll try today

@sergeyklay sergeyklay added this to the 2.0.2 milestone May 12, 2015
@sergeyklay sergeyklay self-assigned this May 12, 2015
@valVk
Copy link

valVk commented May 12, 2015

👍

@sergeyklay
Copy link
Member

@javagrails Can you please try with 2.0.x branch? Probably I fixed this issue earlier

@sergeyklay sergeyklay removed this from the 2.0.3 milestone Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants