通过Zend框架的Doctrine Orm工具
问题描述:
为了在Zend 2项目中使用Doctrine Module ORM工具,我需要通过Zend运行该命令,以便在index.php和application.config.php中定义的引导选项是正确的成立。通过Zend框架的Doctrine Orm工具
这些定义的总和使配置文件被加载,其中包含我希望注入到Doctrine中的数据库设置。这是通过一个自定义的DBALConnectionFactory实现的。
我application.config.php教义的配置是这样的:
'doctrine' => array(
'entity_path' => array (
__DIR__ . '../src/Application/Entity'
),
'driver' => array(
'ApplicationDriver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'ApplicationDriver'
)
)
),
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'DoctrineTypeMappings' => array(
'enum' => "string"
)
)
)
),
'doctrine_factories' => array(
'connection' => 'Application\ORM\DBALConnectionFactory',
),
据山姆how to configure doctrine command line tools on zenframework 2,我应该能够使用
php public/index.php orm:schema-tool:create
但这一切确实为我是列出可用的命令(这表明参数未被正确映射)。
我也曾尝试(从项目根)以下命令无济于事:
php public/index.php doctrine orm:schema-tool:create
php public/index.php doctrine orm orm:schema-tool:create
有没有人有通过Zend的使用原则工具的任何运气?所有回复都非常感谢!
答
该问题是由自定义控制台路由干扰标准路由的参数引起的。我已经修改它将所有通过public/index.php发出的请求直接传递给标准路由器。
public function match(Request $request)
{
// Get command line arguments and present working directory from
// server superglobal:
$filename = $request->getScriptName();
if ("public/index.php" === $filename) {
return parent::match($request);
}
// WARNING: cwd is $APPLICATION_HOME, so that throws off realpath!
//
// Convert base filename (minus .php extension and underscores) and
// containing directory name into action and controller, respectively:
$base = basename($filename, ".php");
$actionName = str_replace('_', '', $base);
$dir = dirname($filename);
//invoked in directory e.g. $base=util/ping.php
$level1 = basename(dirname($filename));
// re-orient relative to APPLICATION_HOME
$path = $level1 . '/' . basename($filename);
$controller = basename($dir);
$routeMatch = new RouteMatch(
array('controller' => $controller, 'action' => $actionName), 1
);
// Override standard routing:
$routeMatch->setMatchedRouteName('default');
return $routeMatch;
}