是否有一种简单的方法将依赖注入到Doctrine2中的每个存储库实例中?
我已经尝试过监听loadClassMetadata事件并在存储库上使用setter注入,但这自然导致无限循环,因为getRepository事件中的调用触发了同一事件.
在看了一下这个Doctrine\ORM\EntityManager::getRepository方法之后,看起来存储库根本就没有使用依赖注入,而是在函数级别实例化它们:
public function getRepository($entityName)
{
$entityName = ltrim($entityName, '\\');
if (isset($this->repositories[$entityName])) {
return $this->repositories[$entityName];
}
$metadata = $this->getClassMetadata($entityName);
$customRepositoryClassName = $metadata->customRepositoryClassName;
if ($customRepositoryClassName !== null) {
$repository = new $customRepositoryClassName($this, $metadata);
} else {
$repository = new EntityRepository($this, $metadata);
}
$this->repositories[$entityName] = $repository;
return $repository;
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
假设我有一个100x100矩阵,我想把它分成10x10的相等部分.
问题是输入矩阵可以是任何大小(但总是mod 10).我查看了该mat2cell功能,但它似乎不适用于动态数量的部件.或者我错过了什么?
我正在尝试在Magento 1.8中以编程方式创建产品,然后为其设置一些属性值.到目前为止,每个工作都在工作,属性正在使用"默认"范围内的产品正确保存.
问题是我的商店有两个不同的"商店视图",一个用英语,一个用法语.我无法想象如何为特定属性的数据设置"范围"或"存储视图".
如何告诉Magento保存特定范围的属性值?
这是使用"简短描述"属性的代码示例:
$product = new Mage_Catalog_Model_Product();
$product->setSku($sku);
$product->setAttributeSetId($attributeSetId);
$product->setTypeId($typeId);
$product->setName($sku);
$product->setWebsiteIDs(array($websiteId));
$product->setShortDescription('Short description in english');
$product->setShortDescription('Short description in french'); // Scope change here?
Run Code Online (Sandbox Code Playgroud) 我有一个表由不同的线程同时读取.
每个线程必须选择100行,在每行上执行一些任务(与数据库无关),然后他们必须从表中删除所选行.
使用此查询选择行:
SELECT id FROM table_name FOR UPDATE;
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何忽略(或跳过)先前在MySQL中使用select语句锁定的行?
我正在使用Doctrine 1.2和Symfony 1.4.
在我的操作中,我有两个不同的查询返回不同的结果集.不知怎的,第二个查询似乎改变了第一个查询的结果(或引用?),我没有任何线索为什么..
这是一个例子:
$this->categories = Doctrine_Query::create()
->from('Categorie AS c')
->innerJoin('c.Activite AS a')
->where('a.archive = ?', false)
->execute();
print_r($this->categories->toArray()); // Return $this->categories results, normal behavior.
$this->evil_query = Doctrine_Query::create()
->from('Categorie AS c')
->innerJoin('c.Activite AS a')
->where('a.archive = ?', true)
->execute();
print_r($this->categories->toArray()); // Should be the same as before, but it return $this->evil_query results instead!
Run Code Online (Sandbox Code Playgroud)
为什么Doctrine这样做?这让我疯狂.谢谢!
为简单起见,似乎查询2正在劫持查询1结果.
我想在加载图像时将图像父级的大小调整为相同大小的图像.
这时候我正在使用这段代码:
$(window).load(function(){
$('.image-principale').each(function(){
$(this).parent().css('height', $(this).height());
});
});
Run Code Online (Sandbox Code Playgroud)
它工作,除了它只在每个图像加载时运行.我试图直接为每个图像添加一个加载处理程序,但它们不会触发.
怎么了?
谢谢!