0

I am new to Magento, I need to pass parameters to a cms page created through the backend under the cms section. The steps I followed to create a page are as follows:

  1. First of all, I added a new page layout using this answer.
  2. Then I added a new page from admin panel, and added the layout created in the previous step to this page.
  3. The page is created and I can access it using the url-key (custom-products) generated for this page, as example.com/custom-products The page content is loaded successfully.

Now my problem is, i want to pass a parameter to this url just like example.com/custom-products/1, but when I write /1 at the end of the url, It takes me to the Not found page.

But when I add a query-string parameters (example.com/custom-products?param=1) to this page the page works fine. But I don't want the parameter passed as query-string. I need it to be as example.com/custom-products/1

Any help in this regard would be really appreciating.

Bundle of thanks in advance.

sv3n
11.7k7 gold badges44 silver badges75 bronze badges
asked Jun 10, 2017 at 21:44
3
  • What is the param /1 for? You could add this to your CMS page url key, but i doubt thats what you're looking for. Commented Jun 11, 2017 at 0:07
  • param /1 is not a static number, it is a dynamic number, which gets value from the previous page Commented Jun 11, 2017 at 0:15
  • OK, what should the parameter do? Just ask because i think a (static) CMS page is not for displaying dymanic content. Maybe you can update your answer and tell what you try to achieve in the end. Commented Jun 11, 2017 at 0:23

2 Answers 2

2

You can't use following type of url for cms page

example.com/custom-products/1 

OR

example.com/custom-products/param/1

Because CMS Router class take whole things as an identifier. In example it's create identifier for url like

custom-products/1

AND

custom-products/param/1

But when you create CMS page, you assign identifier 'custom-products' not custom-products/1 or custom-products/param/1, That's why it load nothing. Check following class

app/code/core/Mage/Cms/Controller/Router.php

/**
 * Validate and Match Cms Page and modify request
 *
 * @param Zend_Controller_Request_Http $request
 * @return bool
 */
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(), '/');
 $condition = new Varien_Object(array(
 'identifier' => $identifier,
 'continue' => true
 ));
 Mage::dispatchEvent('cms_controller_router_match_before', array(
 'router' => $this,
 'condition' => $condition
 ));
 $identifier = $condition->getIdentifier();
 if ($condition->getRedirectUrl()) {
 Mage::app()->getFrontController()->getResponse()
 ->setRedirect($condition->getRedirectUrl())
 ->sendResponse();
 $request->setDispatched(true);
 return true;
 }
 if (!$condition->getContinue()) {
 return false;
 }
 $page = Mage::getModel('cms/page');
 $pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId());
 if (!$pageId) {
 return false;
 }
 $request->setModuleName('cms')
 ->setControllerName('page')
 ->setActionName('view')
 ->setParam('page_id', $pageId);
 $request->setAlias(
 Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
 $identifier
 );
 return true;
}

Check following line


$page = Mage::getModel('cms/page');
$pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId());
if (!$pageId) {
 return false;
}

How to overcome?

Create your own router and make your own way.

How you create Router?

You use an example of CMS module. Open config.xml and check following code sample


<events>
 <controller_front_init_routers>
 <observers>
 <cms>
 <class>Mage_Cms_Controller_Router</class>
 <method>initControllerRouters</method>
 </cms>
 </observers>
 </controller_front_init_routers>
</events>

Create your router class like Vendor_Module_Controller_Router.

answered Jun 11, 2017 at 7:25
0

can you try like that

example.com/custom-products/param/1

you are not passed parameter (param) field in the url.

answered Jun 11, 2017 at 7:00
1
  • if it is work please let me know Commented Jun 11, 2017 at 7:01

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.