繁体   English   中英

创建模型,视图和控制器时,phalcon框架webtools无法正常工作

[英]phalcon framework webtools not working when creating models, views and controllers

我试图让phalcon webtools工作时遇到一些问题。

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

但是,使用webtools并不容易。

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

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

显然,Db连接是可以的,因为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');

我的public / 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 - 适用于PHP 5.4.0的Windows x86(VC9)

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

查看vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
_getConfig函数。

快速而肮脏的解决方案../path

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

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

为了增加一些答案,通过预先添加../以及一些代码更改来编辑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的答案一起在webtools中工作。 请享用。

在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',
    )
);

有点相关,我有一个webtools网址越来越长的问题..最终我可以通过在config.php替换baseUri替换webtools这个词来解决这个问题。

<?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"]
        ),
    ]
]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM