在溃败中不调用Magento控制器方法

时间:2016-12-13 08:08:07

标签: php magento

我试图在url中调用另一个方法exept index mothod of controller,它不是在magento中调用的。我怎样才能在url中调用控制器的其他方法。我的溃败是。本地主机/ sewingapis /类别/索引/ testingMethod。

我的控制器代码是:

/

我的config.xml。

  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';
          }
    }

1 个答案:

答案 0 :(得分:1)

您需要在方法名称中添加Action后缀,与索引操作中添加的内容相同。

 public function testingMethodAction(){
        echo 'hello';
 }