2
我想調用另一個方法exept在url控制器的索引方法,它不在magento中調用。我怎麼能在URL中調用控制器的其他方法。我的路線是。本地主機/ sewingapis /類別/索引/ testingMethod。Magento控制器方法沒有在路由中調用
我的控制器代碼是:
class Product_Category_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$parent = Mage::app()->getStore()->getRootCategoryId();
$tree = Mage::getResourceModel('catalog/category_tree');
/* @var $tree Mage_Catalog_Model_Resource_Category_Tree */
$nodes = $tree->loadNode($parent)
->loadChildren($recursionLevel)
->getChildren();
$tree->addCollectionData(null, false, $parent);
$categoryTreeData = array();
foreach ($nodes as $node) {
$categoryTreeData[$node->getData('entity_id')] = $this->getNodeChildrenData($node);
}
//return $categoryTreeData;
$response['status'] = true;
$response['data'] = $categoryTreeData;
echo json_encode($response);
}
function getNodeChildrenData(Varien_Data_Tree_Node $node)
{
$data = array(
'title' => $node->getData('name'),
'url' => $node->getData('url_key'),
);
foreach ($node->getChildren() as $childNode) {
if (!array_key_exists('children', $data)) {
$data['children'] = array();
}
$data['children'][$childNode->getData('entity_id')] = $this->getNodeChildrenData($childNode);
}
return $data;
}
public function getCatSubCatByProductId()
{
$categoryId = 10;
$products = Mage::getSingleton('catalog/category')->load($categoryId)
->getProductCollection()
->addAttributeToSelect('*');
}
public function testingMethod(){
echo 'hello';
}
}
我config.xml中。
<config>
<modules>
<Product_Category>
<version>0.1.0</version>
</Product_Category>
</modules>
<frontend>
<routers>
<category>
<use>standard</use>
<args>
<module>Product_Category</module>
<frontName>categories</frontName>
</args>
</category>
</routers>
</frontend>
</config>
它解決了我的問題。謝謝Pankaj Pareek。 –