简体   繁体   English

Magento如何克隆自定义集合

[英]Magento how to clone the custom collection

I need to clone my custom collection. 我需要克隆我的自定义集合。

When I'm using the clone it makes it as reference. 当我使用克隆时,它将它作为参考。

In the example below the $myCollection will have the same Select as the cloned on: 在下面的示例中,$ myCollection将具有与克隆相同的Select:

$cloneCollection = clone $myCollection;
$cloneCollection->addFieldToFilter('my_field', 'my_value');

PS. PS。 I saw that you can clone some core collections this way, but it wont work for the custom collections for some reason. 我看到你可以用这种方式克隆一些核心集合,但由于某些原因它不能用于自定义集合。

Thanks. 谢谢。

try this 尝试这个

$cloneCollection = clone $myCollection;
$cloneCollection->clear();
$cloneCollection->addFieldToFilter('my_field', 'my_value');

hope this help you 希望这能帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM