【问题标题】:phalcon framework webtools not working when creating models, views and controllers创建模型、视图和控制器时 phalcon 框架 webtools 不起作用
【发布时间】:2015-02-12 14:23:31
【问题描述】:

我在尝试让 phalcon webtools 工作时遇到了一些问题。

使用命令行开发工具时,我可以毫无问题地创建控制器和模型。

但是,使用网络工具并非易事。

它正确显示了已经创建的控制器和模型:

我也可以编辑它们 (http://i.imgur.com/orJweLl.png)。

显然,Db connexion 没问题,因为 webtools 显示了 DB 中的每个表:

但是,当尝试从 Web 界面创建控制器时,我收到了下一个错误:

"请指定控制器目录"

尝试从数据库表创建模型时也是如此:

“无法从您的配置文件中加载数据库配置”

或者在尝试生成脚手架时:

"在配置中找不到适配器。请指定一个配置变量 [数据库][适配器]"

我的 app/config/config.php 内容:

return new \Phalcon\Config(array(
    'database' => array(
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'phalcon',
        'password'    => 'phalcon',
        'dbname'      => 'phalcon',
        'charset'     => 'utf8',
    ),
    'application' => array(   
        'controllersDir' => __DIR__ . '/../../app/controllers/',
        'modelsDir'      => __DIR__ . '/../../app/models/',
        'viewsDir'       => __DIR__ . '/../../app/views/',
        'pluginsDir'     => __DIR__ . '/../../app/plugins/',
        'libraryDir'     => __DIR__ . '/../../app/library/',
        'cacheDir'       => __DIR__ . '/../../app/cache/',
        'baseUri'        => '/phalconTest/',

    )
));

我的 public/webtools.config.php 内容:

define('PTOOLS_IP', '192.168.248.135');
define('PTOOLSPATH', 'C:/phalcon-devtools');

我的公共/webtools.php:

use Phalcon\Web\Tools;
require 'webtools.config.php';
require PTOOLSPATH . '/scripts/Phalcon/Web/Tools.php';

Tools::main(PTOOLSPATH, PTOOLS_IP);

我正在运行 Phalcon 1.3.4 - Windows x86 for PHP 5.4.0 (VC9)

【问题讨论】:

    标签: php windows phalcon


    【解决方案1】:

    这似乎是 webtools 中的一个错误。

    vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
    _getConfig 功能。

    快速而肮脏的解决方案是将../ 附加到path

    【讨论】:

    • 首先,感谢您的回答。我这样做了,现在控制器代工作!遗憾的是,在尝试创建模型(“无法从您的配置文件中加载数据库配置”)或使用脚手架(“Builder 不知道模型目录在哪里”和“未定义索引:C:\phalcon 中的模型命名空间”时,它仍然失败-devtools\scripts\Phalcon\Builder\Scaffold.php ").
    • 在尝试创建模型时,它还说 PTOOLS_IP 和 PTOOLSPATH 都已定义
    • @MiGU 我找到了,对于模​​型你需要'/../app/config/' 而对于脚手架你需要'../app/config/' 所以你必须改变它制作模型后,您可以制作脚手架。不明白为什么。
    【解决方案2】:

    你需要更改app/config/config.php中的第一行

    defined('APP_PATH') || define('APP_PATH', realpath('..'));

    【讨论】:

      【解决方案3】:

      为了补充一些答案,通过添加 ../ 来编辑 configPath 以及一些代码更改,当 modelPath 被 rtrimmed 时忘记了一点“/”。

      此外,代码将被更新和修复,但到目前为止,可以通过编辑your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php 来解决问题;找到

      $modelsDir = rtrim(rtrim($modelsDir, '/'), '\\') . DIRECTORY_SEPARATOR;
          if ($this->isAbsolutePath($modelsDir) == false) {
              $modelPath = $path . DIRECTORY_SEPARATOR . $modelsDir;
          } else {
            //  $modelPath = $modelsDir;
          // replace or ADD TO LINE ABOVE so it looks like BELOW:
                $modelPath = DIRECTORY_SEPARATOR . $modelsDir;
      }
      

      然后模型将与 TKF's answer 一起在 webtools 中工作。享受吧。

      【讨论】:

        【解决方案4】:

        在 webtools.config.php 中应用更改,如下所示:

        <?php
        
        if (!defined('PTOOLS_IP'))
            define('PTOOLS_IP', '192.168.');
        
        if (!defined('PTOOLSPATH'))
            define('PTOOLSPATH', '/path/to/phalcon/devtools');
        
        return array(
            'application' => array(   
                'controllersDir' => __DIR__ . '/../../app/controllers/',
                'modelsDir'      => __DIR__ . '/../../app/models/',
            ),
            'database' => array(
                'adapter' => 'Mysql',
                'host' => 'localhost',
                'username' => 'usr',
                'password' => 'pwd',
                'dbname' => 'dbname',
            )
        );
        

        【讨论】:

          【解决方案5】:

          有点相关,我遇到了 webtools url 越来越长的问题。最终我可以通过添加单词 webtools 来替换 config.php 中的 baseUri 来解决这个问题。

          <?php ### config.php ... somewhat relevant parts ...
          return new \Phalcon\Config([
              'database' => [ # ... some things ...
              ],
              'application' => [ # ... some more ...
                  // This allows the baseUri to be understand project paths that are not in the root directory
                  // of the webpspace.  This will break if the public/index.php entry point is moved or
                  // possibly if the web server rewrite rules are changed. This can also be set to a static path.
                  'baseUri'        => preg_replace(
                      '/(public([\/\\\\]))?(index)|(webtools).php$/',
                      '',
                      $_SERVER["PHP_SELF"]
                  ),
              ]
          ]);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-07-28
            • 1970-01-01
            • 2021-06-28
            • 2012-01-12
            相关资源
            最近更新 更多