In order to use the Doctrine Module ORM tools for a Zend 2 project, I need to run the command via Zend so that the bootstrapping options defined in index.php and application.config.php are correctly established.
The sum off these definitions enable a config file to be loaded which contains DB settings I wish to inject into Doctrine. This is achieved via a custom DBALConnectionFactory.
The doctrine configuration in my application.config.php is like this:
'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',
),
According to Sam in how to configure doctrine command line tools on zenframework 2 , I should be able to use
php public/index.php orm:schema-tool:create
but all that does for me is to lists the commands available (that suggests that the parameters are not being mapped correctly).
I have also tried (from the project root) the following commands to no avail:
php public/index.php doctrine orm:schema-tool:create
php public/index.php doctrine orm orm:schema-tool:create
Has anyone had any luck using the Doctrine Tools via Zend? All responses gratefully received!
The issue was caused by a custom console route interfering with the parameters for the standard route. I have amended it to pass all requests made via public/index.php straight to the standard router.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.