[英]phalcon framework webtools not working when creating models, views and controllers
I'm having some problems while trying to get phalcon webtools working. 我试图让phalcon webtools工作时遇到一些问题。
When using command line devtools I can create controllers and models without problems. 使用命令行devtools时,我可以毫无问题地创建控制器和模型。
However, things aren't that easy with the webtools. 但是,使用webtools并不容易。
It correctly shows already created controllers and models: 它正确显示已创建的控制器和模型:
And I can also edit them ( http://i.imgur.com/orJweLl.png ). 我也可以编辑它们( http://i.imgur.com/orJweLl.png )。
Apparently, Db connexion is ok, since webtools shows every table in the DB: 显然,Db连接是可以的,因为webtools显示了DB中的每个表:
However, when trying to create a controller from the web interface, I got the next error: 但是,当尝试从Web界面创建控制器时,我收到了下一个错误:
"Please specify a controller directory" “请指定一个控制器目录”
Same when trying to create a Model from a database table : 尝试从数据库表创建模型时相同:
"Database configuration cannot be loaded from your config file" “无法从配置文件中加载数据库配置”
Or when trying to generate scaffold : 或者在尝试生成脚手架时:
"Adapter was not found in the config. Please specify a config variable [database][adapter]" “在配置中找不到适配器。请指定配置变量[数据库] [适配器]”
My app/config/config.php content: 我的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/',
)
));
My public/webtools.config.php content: 我的public / webtools.config.php内容:
define('PTOOLS_IP', '192.168.248.135');
define('PTOOLSPATH', 'C:/phalcon-devtools');
My public/webtools.php: 我的public / webtools.php:
use Phalcon\Web\Tools;
require 'webtools.config.php';
require PTOOLSPATH . '/scripts/Phalcon/Web/Tools.php';
Tools::main(PTOOLSPATH, PTOOLS_IP);
Im running Phalcon 1.3.4 - Windows x86 for PHP 5.4.0 (VC9) 我正在运行Phalcon 1.3.4 - 适用于PHP 5.4.0的Windows x86(VC9)
It seems like a bug in webtools. 这似乎是webtools中的一个错误。
Look at vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
查看vendor/phalcon/devtools/scripts/Phalcon/Builder/Component.php
there is the _getConfig
function. 有_getConfig
函数。
The quick and dirty solution is prepend ../
to path
. 快速而肮脏的解决方案../
于path
。
您需要更改app/config/config.php
的第一行
defined('APP_PATH') || define('APP_PATH', realpath('..'));
To add to some of the answers, the editing of configPath by prepending ../ and also some code changes, has forgotten aa little '/' when modelPath has been rtrimmed. 为了增加一些答案,通过预先添加../以及一些代码更改来编辑configPath,当modelPath被rtrimmed时忘记了一点'/'。
Also, code will be updated and fixed but as of now, one can probably fix the issues by editing your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php
; 此外,代码将被更新和修复,但截至目前,可以通过编辑your/path/phalcon-devtools/scripts/Phalcon/Builder/Model.php
。 find 找
$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;
}
Then Models will work in webtools along with TKF's answer . 然后,模型将与TKF的答案一起在webtools中工作。 Enjoy. 请享用。
Apply changes in webtools.config.php like here: 在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',
)
);
Somewhat related, I had an issue with the webtools url getting longer and longer .. Eventually I could fix this by adding the word webtools
in a replacement for the baseUri
in config.php
. 有点相关,我有一个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.