我正在从CSV导入数据,并且已成功通过使用$this->Book->set()
函数并在其中传递包含所有fieldName => value
对的哈希函数来在代码中成功手动设置数据字段。将CakePHP HABTM模型与视图关联
如何在代码中创建habtm关联?我在文档中看到的所有示例均基于从视图中的表单返回的$this->data
。因为我的数据来自csv文件而不是视图,所以我不能使用它!
所以在下面的例子:
// Book habtm Tags
// Tag habtm Books
$this->Book->create();
$this->Book->set(
array(
'author' => 'tolkein',
'title' => 'lord of the rings')
);
$arrayOfTagIds = array(1, 5, 6);
// Do something with $arrayOfTagIds...
$this->Book->save();
我怎么会随书$ arrayOfTagIds关联?
作为一个边注:他叫托尔金;) –