我正在尝试使用Doctrine 1.2的搜索行为为我的项目构建一个搜索引擎,我遵循了手册的建议,并使用我的搜索字段的引用构建了一个YAML。并调用generateModelsFromYaml函数来创建我的php模型,所有的php模型创建都没有错误,但是搜索索引表的模型丢失了……
我的YAML文件的摘录:
DIFFichier:
tableName: ens_diffusion.DIF_Fichiers
columns:
DOC_Id:
type: integer(4)
primary: true
notnull: true
autoincrement: true
DOC_Categorie:
type: integer(4)
default: 0
DOC_Description:
type: string(256)
DOC_Adresse:
type: string(256)
options:
charset: utf8
type: InnoDB
actAs:
Searchable:
fields: [DOC_Description] 可分字段是在模型中生成的,在这里我正确地生成了一个名为"DIFFichier“的模型,但缺少相应的索引表”d_i_f_fichier_index
$searchable0 = new Doctrine_Template_Searchable(array(
'fields' =>
array(
0 => 'DOC_Description',
),
));
$this->actAs($searchable0);我以这种方式生成PHP模型
include_once "Doctrine-1.2.3/Doctrine.php";
spl_autoload_register(array('Doctrine', 'autoload'));
Doctrine::generateModelsFromYaml(
'diffusion2.yml',
'C:\Documents and Settings\admin\Desktop\modelsDoctrine',
array(
'doctrine'
),
array(
'classPrefix' => 'Diffusion_Model_',
'classPrefixFiles' => false
)
);我仍然无法生成我的索引表,有没有其他方法可以从我的YAML文件生成我的表?
发布于 2011-06-16 23:48:40
我终于找到了答案:
首先,索引表似乎不是由generateModelsFromYaml()方法生成的,而更可能是由Doctrine直接在数据库上根据需要创建的……
因此,我尝试通过在以前生成的模型上使用generateSqlFromArray()来手动生成它们,但是Doctrine在创建主键的字段时抛出了一个异常。经过研究,我发现在创建索引表的情况下,被索引的主键必须是小写的。
但是数据库的方案是锁定的。所以我找到了一个变通方法:
<代码>F29
现在一切正常,即使是我的原始模型,尽管它们的主键仍然是大写的…
下面是我创建的用来将主键小写的脚本
$src = file_get_contents("source.yml");
//Lower case the primary key
$src = preg_replace("/([A-Z]{3}_[A-Z]{1}[a-z]*:)/e", "strtolower('\\1')", $src);
file_put_contents("source_lower.yml", $src);现在是生成索引表的SQL创建代码的脚本
require_once("../config.php");
$tables = array();
$dirname = '../include/models/generated/';
$dir = opendir($dirname);
//Extract the classname from the filenames
while($file = readdir($dir)) {
if($file != '.' && $file != '..' && !is_dir($dirname.$file)){
$classe = substr($file, 4, strlen($file) -8);
$tables[] = $classe;
}
}
//Generate SQL create for index tables
foreach($tables as $t){
$sql = Doctrine_Core::generateSqlFromArray(array($t));
afficher($sql[1]);
}
//Print the SQL code if CREATE
function afficher($str){
if(substr($str, 0, 6) == "CREATE"){
echo $str.";<br/>";
}
}https://stackoverflow.com/questions/6356520
复制相似问题