【发布时间】:2014-06-26 07:45:54
【问题描述】:
我正在尝试使用 Magento 中的 PHP 代码在主页上显示推荐
我已经用 getCollection 或不带 getCollection 函数尝试了下面的代码
$collection = Mage::getModel('turnkeye/testimonial');
我可以调用正确的模型吗??
【问题讨论】:
标签: magento magento-1.8
我正在尝试使用 Magento 中的 PHP 代码在主页上显示推荐
我已经用 getCollection 或不带 getCollection 函数尝试了下面的代码
$collection = Mage::getModel('turnkeye/testimonial');
我可以调用正确的模型吗??
【问题讨论】:
标签: magento magento-1.8
模块初始化代码应该是turnkeye_testimonial/testimonial 而不是turnkeye/testimonial
如果您想要按单个项目的字段,那么您可以通过primary key of testimonial table 执行此操作
.
$collection $model = Mage::getModel('turnkeye_testimonial/testimonial')>load(id);
如果你想获取多个项目,那么你需要资源集合
Mage::getResourceModel('turnkeye_testimonial/testimonial')->addFieldToSelect('*');
或
$collection = Mage::getModel('turnkeye_testimonial/testimonial')->getCollection();
对于 随机收集
$collection=Mage::getModel('turnkeye_testimonial/testimonial')->getCollection();
$collection->getSelect()->order('rand()');
一些参考
http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/
【讨论】: