Magento:如何在cms页面上显示所有产品的所有评论

Magento:如何在cms页面上显示所有产品的所有评论,magento,review,Magento,Review,我想在cms页面上显示我对所有产品的所有评论。有人知道怎么做吗?我使用的是Magento 1.4.2,这完全取决于您使用什么模块来扩展Magento的功能。如果您查看模块的文件夹(比如它的Cmdcentral/Review) 这就是模块所在的位置(可能也是本地的)查看etc中的config.xml将有一个类似以下内容的部分: <config> ... <global> .... <models> <review>

我想在cms页面上显示我对所有产品的所有评论。有人知道怎么做吗?我使用的是Magento 1.4.2,这完全取决于您使用什么模块来扩展Magento的功能。如果您查看模块的文件夹(比如它的Cmdcentral/Review)

这就是模块所在的位置(可能也是本地的)查看
etc
中的
config.xml
将有一个类似以下内容的部分:

<config>
 ...
   <global>
    ....
    <models>
      <review>
          <class>Cmdcentral_Review_Model</class>
      </review>
      <review_mysql4>
         <class>Cmdcentral_Review_Model_Mysql4</class>
         <entities>
              <reviews>table_in_database</reviews>
         </entities>
      </review_mysql4>
   </models>
  .....
 </global>
  ...
</config>
public function showallAction(){
   $this->loadLayout();
   $this->renderLayout();

}
<?php class Cmdcentral_Review_Block_Showall extends Mage_Core_Block_Template{
   public function getAllReviews(){
       return Mage::getModel('review/reviews')->getCollection();
   }
}
$reviews = $this->getAllReviews();
foreach($reviews as $review){
  echo $review->getData('column_name');
  #or
  echo $review->getColumnName();
  #does the same thing
}
现在您必须为此创建一个块,在
app/code/community/Cmdcentral/Review/Blocks
中创建一个新块,并将其命名为
Showall.php

您的块应该如下所示:

<config>
 ...
   <global>
    ....
    <models>
      <review>
          <class>Cmdcentral_Review_Model</class>
      </review>
      <review_mysql4>
         <class>Cmdcentral_Review_Model_Mysql4</class>
         <entities>
              <reviews>table_in_database</reviews>
         </entities>
      </review_mysql4>
   </models>
  .....
 </global>
  ...
</config>
public function showallAction(){
   $this->loadLayout();
   $this->renderLayout();

}
<?php class Cmdcentral_Review_Block_Showall extends Mage_Core_Block_Template{
   public function getAllReviews(){
       return Mage::getModel('review/reviews')->getCollection();
   }
}
$reviews = $this->getAllReviews();
foreach($reviews as $review){
  echo $review->getData('column_name');
  #or
  echo $review->getColumnName();
  #does the same thing
}
这只是告诉Magento,当我们加载
review/index/showall
路由并访问控制器中的
showalAction()
函数时,将块添加到内容中

现在,该块还有一个
template=“review/showall.phtml”
属性。转到
app/design/frontend/base/default
查找
review
目录(或任何模块名称)。如果它不存在(我怀疑),就创造它!在这个文件中创建
showall.phtml
。所以现在你应该让它看起来像
app/design/frontend/base/default/review/showall.phtml

打开此文件,现在创建页面~呸

请记住使用
$this->getAllReviews()
获取您的review/reviews集合,然后简单地执行以下操作:

<config>
 ...
   <global>
    ....
    <models>
      <review>
          <class>Cmdcentral_Review_Model</class>
      </review>
      <review_mysql4>
         <class>Cmdcentral_Review_Model_Mysql4</class>
         <entities>
              <reviews>table_in_database</reviews>
         </entities>
      </review_mysql4>
   </models>
  .....
 </global>
  ...
</config>
public function showallAction(){
   $this->loadLayout();
   $this->renderLayout();

}
<?php class Cmdcentral_Review_Block_Showall extends Mage_Core_Block_Template{
   public function getAllReviews(){
       return Mage::getModel('review/reviews')->getCollection();
   }
}
$reviews = $this->getAllReviews();
foreach($reviews as $review){
  echo $review->getData('column_name');
  #or
  echo $review->getColumnName();
  #does the same thing
}
我希望这有帮助,我没有犯任何错误。记住,一开始,Magento会让你哭泣,但当你习惯了Magento,它就会变成断断续续的呜咽