【问题标题】:Calling testimonial module in magento using code使用代码在magento中调用推荐模块
【发布时间】:2014-06-26 07:45:54
【问题描述】:

我正在尝试使用 Magento 中的 PHP 代码在主页上显示推荐

我已经用 getCollection 或不带 getCollection 函数尝试了下面的代码

$collection = Mage::getModel('turnkeye/testimonial');

我可以调用正确的模型吗??

【问题讨论】:

    标签: magento magento-1.8


    【解决方案1】:

    模块初始化代码应该是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/

    【讨论】:

    • 如果我尝试了 Mage::getModel('turnkeye/testimonial'),它什么都没有显示,但如果我使用 ->load、addfieldtoselect 或 getCollection,它会终止页面(意味着错误)
    • 首先 .. 你想要什么收集你的个人物品
    • 我想要收集推荐信
    • 我怎样才能随机获得推荐
    猜你喜欢
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多