【发布时间】:2011-10-22 12:38:11
【问题描述】:
我创建了一个简单的自定义模块,在主页上显示我的类别,为此我在我的自定义模块中创建了一个模型文件和一个块文件。并在我的 CMS(主页)中输入了这一行
{{block type="Definitivemagento_Helloword/randomproducts"}}
现在我希望使用模板(Phtml 文件和 Xml 文件)做同样的事情,因为我想添加一些我想用 Phtml 文件做的 css 和设计部分。有可能吗..这是我当前的模型类和块类代码。
class Pragtech_Sweet_Block_Category extends Mage_Core_Block_Template
{
protected function _toHtml()
{ $catModel = Mage::getModel('Pragtech_Sweet/category');
$myCategory = $catModel->getCategory();
$html = "<ul>";
foreach ($myCategory as $category)
{
$name = $category->getName();
$categoryLink = this->helper('catalog/category')->getCategoryUrl($category);
$html .= "
<p>
<a href='$categoryLink'>$name</a><br/>
<!-- $name <br/> -->
</p>";
}
$html .= "<ul>";
//echo "<pre>"; print_r($html); exit;
return $html;
}
}
我的模型类是:-
Class Pragtech_Sweet_Model_Category extends Mage_Core_Model_Abstract
{
public function getCategory()
{
$categoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name');
$categoryCollection->getSelect()->order(entity_id);
//print_r($categoryCollection); exit;
return $categoryCollection;
}
【问题讨论】:
标签: magento-1.4 magento-1.5 magento