s3v*_*v3n 9 php zend-framework magento zend-db-table zend-db
我和Magento一起工作了一年,并且学到了很多东西.现在我想学习Zend,我坚持使用模型.
我已经习惯了有实体和实体的集合中Magento的,并且很可能我会想使用Zend_Db_Table,Zend_Db_Table_Row和/或Zend_Db_Table_Rowset.我感到困惑的是每个班级的角色.
我知道我可以扩展每个类,我知道在我的Product_Table类(扩展Zend_Db_Table_Abstract)中,可以使用私有方法告诉Zend用于行和行集的类,但是我对它感觉不舒服.
在Magento中使用此代码:
例1
// I understand that maybe I'll use the `new` keyword instead
// Mage::getModel() is only for exemplification
$product = Mage::getModel('catalog/product');
$product->setName('product name');
$product->setPrice(20);
$product->save();
if($id = $product->getId()){
echo 'Product saved with id' . $id;
}
else{
echo 'Error saving product';
}
Run Code Online (Sandbox Code Playgroud)
例2
$collection = Mage::getModel('catalog/product')->getCollection();
// this is the limit, I'm ok with other method's name
$collection->setPageSize(10);
$collection->load()
foreach($collection as $product){
echo $product->getName() . ' costs ' . $product->getPrice() . PHP_EOL;
}
Run Code Online (Sandbox Code Playgroud)
我如何在Zend Framework中实现类似的东西?或者,如果这是一个非常糟糕的想法,那么在Zend Framework中实现模型的最佳实践是什么?
谢谢