3

I created my custom module under local the name is MyTest/ProductsData, what I need to do is to create the new router so I've been created the IndexController.php and my config.xml, and I already activated my custom module and I checked under system->configuration->advanced which is enabled, the URL I'm trying to test is http://example.com/magento/MyTest/index/ or http://example.com/magento/index.php/MyTest/index/index and any other possible URLs also I tried them, all will go to 404 page and I cannot find any solution to solve this problem :( I really appreciate if any of you can help me out with this.

IndexController.php

<?php

class MyTest_ProductsData_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
         echo 'me';
    }

    public function addAction()
    {
        echo 'Test add Action';
    }
    public function deleteAction()
    {
        echo 'Test delete Action';
    }
}

and config.xml file,

<?xml version="1.0"?>
<config>
    <modules>
        <MyTest_ProductsData>
            <version>1.0.0</version>
        </MyTest_ProductsData>
    </modules>
    <global>
        <helpers>
            <mytest_productsdata>
                <class>MyTest_ProductsData_Helper</class>
            </mytest_productsdata>
        </helpers>
    </global>
    <frontend>
        <routers>
            <MyTest>
                <use>standard</use>
                <args>
                    <module>MyTest_ProductsData</module>
                    <frontName>MyTest</frontName>
                </args>
            </MyTest>
        </routers>
    </frontend> 
</config>
  • May be controller file permission is not set to 777. – Manikandan Arunachalam Dec 22 '14 at 9:06
  • I already changed the permission to 777 :( – Saghi Ghorbani Dec 22 '14 at 9:13
  • Run compilation and remove cache too.. – Manikandan Arunachalam Dec 22 '14 at 9:22
  • yeah did it already cannot get to the right page :( still get to 404 page! – Saghi Ghorbani Dec 22 '14 at 9:27
  • check is your controller file exist in magento includes->src->MyTest->ProductsData directory . – Manikandan Arunachalam Dec 22 '14 at 9:30
0

If you dont have MyTest_ProductsData.xml inside your app->etc->modules directory create first..

If you have created already,then check your folder structure and give 777 permission to your module root directory MyTest.

After this Run Compilation process in admin and clear the cache and then check .

EDIT

I have tried your code and it worked for me with this url localhost/magento/MyTest/. Try again..

FILES

controller, config.xml .

  • I have, actually I've activated my module inside that file then already checked it through admin panel, system->configuration->advanced, is enabled. – Saghi Ghorbani Dec 22 '14 at 9:54
  • @SaghiGhorbani I've edited my answer check it now. – Manikandan Arunachalam Dec 22 '14 at 10:29
  • I already run compilation process in admin and clear the cache Disabled everything under cache storage management and clear cache again and I tried with the link you gave its so strange It still doesn't work for me !! :( – Saghi Ghorbani Dec 23 '14 at 2:42
  • Finally, it worked , thanks for your help :), the problem was I should put the routeName before UrlName, defined in config.xml – Saghi Ghorbani Dec 23 '14 at 4:07
  • @SaghiGhorbani sounds good.. – Manikandan Arunachalam Dec 23 '14 at 4:29
-1

Your router has to be as this.

<?php 

class Test_Modulename_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract {

    public function initControllerRouters($observer) {

        $front = $observer->getEvent()->getFront();

        $pressrelease  = 'custom_url_identifier';

        $front->addRouter($pressrelease, $this);     

        }

     public function match(Zend_Controller_Request_Http $request) {  
         if (!Mage::isInstalled()) {
            Mage::app()->getFrontController()->getResponse()
                ->setRedirect(Mage::getUrl('install'))
                ->sendResponse();
            exit;
        }

        $router_name = 'custom_router_name';
        $identifier = trim($request->getPathInfo(), '/');

        if($router_name != $identifier)
        {
             $pressUrl = explode("/",$identifier);
             $pressUrl = $pressUrl[1];
             if($pressUrl != "")
             {
             }
                $collection = Mage::getModel('pressrelease/pressrelease')->getCollection()->addFieldToFilter('url',$pressUrl);
             if(count($collection))
             {
                 foreach ($collection as $_press)
                 {
                    $pressId = $_press['pressrelease_id'];
                    $pressName = $_press['title'];

                       $request->setModuleName('pressrelease')
                        ->setControllerName('pressitem')
                        ->setActionName('view')
                        ->setParam('pressrelease_id', $pressId)
                       ->setParam('title', $pressName);
                       return true;
                 }
             }else
             {
                 $pageId = Mage::getStoreConfig('cms/index/noRoute');
                 $url = rtrim(Mage::getUrl($pageId),'/');
                 Mage::app()->getFrontController()->getResponse()->setRedirect($url);
                 return false;
             }
        }

        $request->setModuleName('pressrelease')
            ->setControllerName('index')
            ->setActionName('index');

        return true;

     }

}

In the events section of config.xml, add this:

 <controller_front_init_routers>
                <observers>
                    <modulesname>
                        <class>Test_Modulename_Controller_Router</class>
                        <method>initControllerRouters</method>
                    </modulesname>
                </observers>
            </controller_front_init_routers>
  • Sry u mean I need to create another file under Controller named Router.php and put this code in? – Saghi Ghorbani Dec 22 '14 at 9:15
  • I got 'Front controller reached 100 router match iterations' this error ! – Saghi Ghorbani Dec 22 '14 at 9:25
  • You need to comment the frontend section in the config.xml, when you are using this method. – Pavan Kumar Jan 7 '15 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.