我遇到了完全相同的情况,最终编写了自己的函数来解决它。这个函数遍历我的 YAML 文件,读取每个表名,并添加className:
不带表前缀的适当条目。
这是功能:
const TABLE_PFX = 'tableName:';
const CLASS_PFX = 'className:';
function AddClassNames($yamlPath) {
$tempFilePath = $yamlPath . '.old';
rename($yamlPath, $tempFilePath);
$tempFile = fopen($tempFilePath, 'r');
$yamlFile = fopen($yamlPath, 'w');
while (!feof($tempFile)) {
$line = fgets($tempFile);
fwrite($yamlFile, $line);
if ($index = strpos($line, TABLE_PFX)) {
$tableName = trim(substr($line, $index + strlen(TABLE_PFX) + 1));
$className = substr($tableName, 4);
$className = strtocamel($className);
$classLine = str_replace(TABLE_PFX, CLASS_PFX, $line);
$classLine = str_replace($tableName, $className, $classLine);
fwrite($yamlFile, $classLine);
}
}
fclose($tempFile);
fclose($yamlFile);
unlink($tempFilePath);
}
这是我使用它的方式:
Doctrine_Core::generateYamlFromDb($yamlPath);
AddClassNames($yamlPath);
Doctrine_Core::generateModelsFromYaml($yamlPath, 'models',
array('doctrine'),
array('generateTableClasses' => true,));
进一步说明 - 使用这种方法,您无法将 Doctrine 转换database_table_name
为 PHP 友好的ClassName
,因此您必须自己执行此操作。我使用了这里strtocamel
的功能。