0

I search the entire web to found solutions for rewriting an url from a custom action but nothing works.

I tried to put into global this :

<rewrite>
 <artist_list_index>
 <from><![CDATA[#artist/list/index#]]></from>
 <to><![CDATA[artists]]></to>
 <complete>1</complete>
 </artist_list_index>
 </rewrite>

It gives me a 404 when i try to reach artist/list/index or artists route.

I tried to put this in gobal :

<routers>
 <artist>
 <rewrite>
 <list>
 <to>artists</to>
 </list>
 </rewrite>
 </artist>
 </routers>

I can real artist/list/index but artists gives me a 404. I think i understand why by checking the _rewrite function. It's because this allow to override a function from a controller by forwaring a route to another.

Finally i tried to create my own router and then i get this error "Front controller reached 100 router match iterations ". So in global i added this :

<events>
 <controller_front_init_before>
 <observers>
 <artist_rewrite>
 <class>Confidential_Artist_Controller_Router</class>
 <method>insertControllerRouter</method>
 </artist_rewrite>
 </observers>
 </controller_front_init_before>
 </events>

Confidential_Artist_Controller_Router functions are :

/**
 * Initialize Controller Router
 *
 * @param Varien_Event_Observer $observer
 */
 public function insertControllerRouter($observer)
 {
 /* @var $front Mage_Core_Controller_Varien_Front */
 $front = $observer->getEvent()->getFront();
 $front->addRouter('artist', $this);
 }
 /**
 * @param Zend_Controller_Request_Http $request
 * @return bool
 * @throws Mage_Core_Model_Store_Exception
 */
 public function match(Zend_Controller_Request_Http $request)
 {
 if (!Mage::isInstalled()) {
 Mage::app()->getFrontController()->getResponse()
 ->setRedirect(Mage::getUrl('install'))
 ->sendResponse();
 exit;
 }
 $requestPathInfo=trim($request->getPathInfo(),'/');
 if($requestPathInfo != 'artists'):
 return false;
 endif;
 $request->setModuleName('artist')
 ->setControllerName('list')
 ->setActionName('index');
 $request->setAlias(
 Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
 $requestPathInfo
 );
 return true;
 }

Finally, here is my action controller definition :

 <routers>
 <artist>
 <use>standard</use>
 <args>
 <module>Confidential_Artist</module>
 <frontName>artist</frontName>
 </args>
 </artist>
 </routers>

Can you help me please ? i don't know what's wrong.

asked Jun 4, 2018 at 9:46

1 Answer 1

0

I don't understand how the function match works but i found a solution.

I changes this function in this :

public function match(Zend_Controller_Request_Http $request)
 {
 if (!Mage::isInstalled()) {
 Mage::app()->getFrontController()->getResponse()
 ->setRedirect(Mage::getUrl('install'))
 ->sendResponse();
 exit;
 }
 $identifier = trim($request->getPathInfo(), '/');
 if ($identifier == 'artists') {
 $request->setModuleName('artist')
 ->setControllerName('list')
 ->setActionName('index');
 $request->setAlias(
 Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
 $identifier
 );
 }
 return false;
 }

I don't understand if this is follow the magento standards. Can you give me more precisions please ?

answered Jun 4, 2018 at 11:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.